| Keywords | |||||||
|---|---|---|---|---|---|---|---|
| and | assert | as | break | class | continue | def | del |
| elif | else | except | exec | finally | for | from | global |
| if | import | in | is | lambda | not | or | pass |
| raise | return | try | while | with | yield |
In [3]:
# this is a correct variable name
variable_name = 10
In [4]:
# this is not a correct variable name - variable names can't start with a number
4tops = 5
In [4]:
# here's the error generated from using a Python keyword - notice the color of the variable name: it's not the same
# as the one in the cells below
finally = 7
In [6]:
# these variables are not the same
distance = 10
Distance = 20
disTance = 30
print "distance = ", distance
print "Distance = ", Distance
print "disTance = ", disTance
In [7]:
x = 11
if x == 10:
print 'x = 10'
else:
print 'x != 10'
print 'Done'
print "Bye now"
A new line signals the end of a statement
In [ ]:
# these are two separate statements
a = 4
b = 6
For multi-line statements, use the \ character at the end of the line
In [10]:
# use line continuation symbol (use with care)
a = 10 \
+ \
10 + 10
print a
or put the multilines in ()
In [5]:
# use prenthesis (preferable way) to have a multiline statements
a = (10
+ 20 +
10 + 10)
print a
In [6]:
# this is a line comment
a = 10 # this is also a line comment
'''
this line is indsie a multi-line comment
so is this
and this
'''
a = 100 # this is outside the multi-line comment
"""
This is another way to declare a multi-line comment
Inside it
inside it too
"""
a = 100 # this is outside the multi-line comment
You can put a comment inside a muliline statement
In [1]:
# multiline statement with comments
a = (10 # this is line 1
+ 20 + # this is line 2
10 + 10)
print a