Python 1
Python 1
(portable)
(non-portable)
Interpreter
Compiler
Input
Output
Math
Conditional execution
Repitation
Debugging
Runtime error
Semantic error
print "Hello 1st sem"
print 56
print 3.4
type (54)
type (3.4)
type ("54")
type ("3.4")
print 1,000,000
Variable
message="get up guys"
n=17
pi=3.14
print message
print n
print pi
type (message)
type (n)
type (pi)
Mathematical operator
+ - * / ** % //
min=59
min/60
100*min/60
PEDMAS [B O D M A S]
"apple"+"banana"
"Fun"*3 = "Fun"+"Fun"+"Fun"
http:/docs.python.org/27/tutorial/
>>> word = 'Python'
>>> word[0] # character in position 0
'P'
>>> word[5] # character in position 5
'n'
Indices may also be negative numbers, to start counting from the right:
Note that since -0 is the same as 0, negative indices start from -1.
Note how the start is always included, and the end always excluded. This makes
sure that s[:i] + s[i:] is always equal to s:
Slice indices have useful defaults; an omitted first index defaults to zero, an
omitted second index defaults to the size of the string being sliced.
The first row of numbers gives the position of the indices 0…6 in the string; the
second row gives the corresponding negative indices. The slice from i to j consists of
all characters between the edges labeled i and j, respectively.
For non-negative indices, the length of a slice is the difference of the indices, if both
are within bounds. For example, the length of word[1:3] is 2.
However, out of range slice indexes are handled gracefully when used for slicing:
>>> word[4:42]
'on'
>>> word[42:]
''
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
34