Part one: Learn the Basics
Hello, World!
print "Hello,World!"
Variables and Types
Python is completely object oriented, and not "statically typed.
You don't need to delcare variables before using them, or delcare
their type. Every variable in Python is an object.
Numbers:
Python supports two types of numbers -integers and floating point numbers.(It also suports complex numbers)
To define an integer, use the following syntax:
aint = 7
To define a floating point number, you may use one of the following notations:
afloat = 7.0
anotherfloat = float(7)
Strings are defined either with a single quote or a double quotes:
astring = 'hello'
anotherstring = "hello"
The difference between the two is that using double quotes makes it easy to include apostrophes (whereas these would terminate the string if using single quotes)
There are additional variations on defining strings that make it easier to include things such as carriage returns.
backslashes and unicode characters.
Lists are very similar to arrays.They can contain any type of variable.Lists can aslo be iterated over in a very simple manner.
mylist = []
mylist.append(1)
mylist.append(2)
mylist.append(3)
# prints out 1,2,3
for x in mylist:
print x