In this tutorial you'll learn a few things abotu python programming software
1st step:
So now go to start menu, find python and run the program '"IDLE" (Stands for Integrated Development Environment) it's like C++
IDLE is the basic tool you'll be working with. Try some codes.explore the python IDLE environment
2nd step:
Type the following and press enter: (don't type >>> as it should already be there)
CODE
print "Hello, world"
You just created a program, that prints the words 'Hello, World'. The IDLE environment that you are in immediately compiles whatever you have typed in. This is useful for testing things, e.g. define a few variables, and then test to see if a certain line will work.
Now moving to another part of programming which is maths...
3rd step:
type these stuff:
CODE
>>> 1 + 1
2
>>> 20+80
100
>>> 18294+449566
467860
(These are additions)
>>> 6-5
1
(Subtraction)
>>> 2*5
10
(Multiply, rabbits!)
>>> 5**2
25
(Exponentials e.g. this one is 5 squared)
>>> print "1 + 2 is an addition"
1 + 2 is an addition
(the print statement, which writes something onscreen)
>>> print "one kilobyte is 2^10 bytes, or", 2**10, "bytes"
one kilobyte is 2^10 bytes, or 1024 bytes
(you can print sums and variables in a sentence.
The commas seperating each section are a way of
seperating clearly different things that you are printing)
>>> 21/3
7
>>> 23/3
7
>>> 23.0/3.0
7.6666...
(division, 2nd time ignoring remainder/decimals,
3rd time including decimals)
>>> 23%3
2
>>> 49%10
9
(the remainder from a division)
these are the basics. You might learn in school about -,*,+ etc.
QUOTE
eg.
command name example output
+ Addition 4+5 9
- Subtraction 8-5 3
* Multiplication 4*5 20
/ Division 19/3 6
% Remainder 19%3 5
** Exponent 2**4 16
Remember that thing called order of operation that they taught in maths? Well, it applies in python, too. Here it is, if you need reminding:
1. parentheses ()
2. exponents **
3. multiplication *, division \, and remainder %
4. addition + and subtraction -
ok that's what you should know about maths in python let's move further:
Now about comments:
4th step:
type:
CODE
>>> #I am a comment. Fear my wrath!
A comment is a piece of code that is not run. In python, you make something a comment by putting a hash in front of it. A hash comments everything after it in the line, and nothing before it. So you could type this:
CODE
>>> print "food is very nice" #eat me
food is very nice
(a normal output, without the smutty comment,
thankyou very much)
>>># print "food is very nice"
(nothing happens, because the code was after a comment)
>>> print "food is very nice" eat me
(you'll get a fairly harmless error message,
because you didn't put your comment after a hash)
Comments are important for adding necessary information for another programmer to read, but not the computer. For example, an explanation of a section of code, saying what it does, or what is wrong with it. You can also comment bits of code by putting a # in front of it - if you don't want it to compile, but cant delete it because you might need it later.
Part 2 later ^^