Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 03-06-2010, 09:08 PM   #1 (permalink)
Rox
Right Off the Assembly Line
 
Join Date: Jun 2010
Posts: 5
Default Python Basics #1 [ n00b Friendly]


[size=medium][align=center]Beginner's Python
-Rox
[/align][/size]



If you dont know programming, It is the way in which we tell computer to do something, step by step. Each step is called a command.
For example, If we are to make computer drink a tea, the steps are getup from table, go to table and take tea. We should not say, Take tea, it is in table. It is ok for friends to understand but computer doesnt.


About Python
==
  • Python is cross platform, meaning it can be run on windows, linux, mac, everything.
  • Python saves files in .py extension.
  • Python is relatively simple.
  • Python is low-performance language[Is slow to run, unlike C++,C# etc.]
  • Python is a high level language[More closer to humans than machines]

Downloading Compiler
==

Download from here and install it.
Now open Python GUI[IDLE] from Start Menu --> Python.

So that is a 'Compiler' and that is where we type in our programming 'commands'

Hello World
==

If you have programming experience before, unlike other languages like C++ or VB, we dont need header files or other things.
For simply outputting 'Hello World', we simple type:
Code:
"Hello World"
in the Python GUI And Press Enter. It will print 'Hello World'.
If you have Quotes in the program itself, ad a \[backslash] before it.



Mathematics in Python
==

Maths Functions work on python simply like you are writing it on a calculator.
For eg, Typing 2+2 and pressing Enter gives 4.
Typing 2*2 and pressing Enter gives 4.
Typing 2/2 gives 1.
However, if u type 3/2, it also gives 1 with no decimal. To have decimal in your program , you have to give a decimal to either numberator(3) or denominator(2).
eg 3.0/2 = 1.5

Compiling - It is how we convert our 'English-like' language into numbers that computer can understand(0s and 1s)

If you want the remainder of something, for example, if you want the remainder of 3/2, you use the '%' symbol between 3 and 2.
ie, 3%2 gives the remainder of 3/2 which is 1.

We call '%' modulus.
Now, if you want the power of a number , you use two stars(*) .
For example if you want the power of 2 raised to 5, you write 2**5 and it gives you 2^5 which is 32.

All the above rules applies to -(ve) numbers also.


Variables
======

Variables are letters or symbols which act as temporary storage values for numbers.
For example, x is a variable. apple is a variable. Only if we assign x and apple numerical values like
x=5, apples = 1000 etc.
So how do we assign values in python?

Unlike other languages, you dont need to 'declare' a variable first.
Just typing
x = 5
in the promt assigns 'x' the value of 5.
now, if we type x + 10 and press enter, we get 15, since value of x is 5 and hence is x+5.
We can also assign multiple variables like x = 5, apples = 85 and then if we do
x + apples
we get 90.

Now these type of declarations at the time of programing is called 'Compile time initialization' mostly used term in C++. So we, the programmers declare the variable at the time of writing code.
Now, if we are going to code something like a calculator, it should be the user that types the values. For that, we use 'input' function,

for example, typing
Code:
f = input("Enter Number: ")
and pressing enter displays
Enter Number: _
And we enter a number. That value is assigned to 'f'.
So that is all about variables in python. Now try making a calculator.

For that we need multiple line commands. Go to File-->New Window. And type the codes there.
in there,if we type "hello world", its not gonna display "Hello WOrld". for that, we need to type
print "Hello World".

Then type the variables and other things. Also, to run the program, go to 'Run' in the new window and Press 'Run Module'. Press ok if it asks to save.

So Hope you learnt something. Thanks for reading.
Rox is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
eBook for Python abhijangda Programming 8 09-06-2010 12:56 PM
Sorting a multidimensional list in python bharat_r Programming 1 09-04-2010 12:24 PM
Help in python abhijangda Programming 3 09-04-2010 12:06 PM
Wannabe Python Programmer - Please Help ! MetalheadGautham Programming 22 13-08-2008 11:27 AM
One Giant Command Line MetalheadGautham Open Source 23 24-05-2008 02:31 AM

 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:18 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2