Python

Syntax

  keywords example
Assignment    

Functions
Objects

def return yield
class
 
Call    
Conditinal if elif else
and or not
 
Loops for else
in
while else
break continue
for i in range(0,5)
for i in xrange(0,5)
Exceptions try except finally
raise
 
Other reseved words pass
import from
global
del
exec
assert
is
 
  lambda
print
 

 

Types

Numbers

python numbers

functions are defined in the following modules:

  import module  
floating point numbers math  
complex numbers cmath  

Collections

python collections

String

s = 'abc'

or s = "abc"

slicing:

s[0:1] gives 'ab'

s[1:] gives 'bc'

s[:1] gives 'ab'

Tuple

t = (1,2,3)

Lists

l = [1,2,3]

Dictionary

d = {'first':1,'second':2,'third':3}


metadata block
see also:

Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2022 Martin John Baker - All rights reserved - privacy policy.