print 'Hello ' + 'world' print a |
|
Get input raw_input |
name= raw_input('type in name') |
| Make an integer (whole number) | int(a) |
| Make a string (text) | str(a) |
| For loop |
|
| While loop | ![]() |
| To end a loop early | break |
| If else | ![]() |
Else if elif |
![]() |
| Logical expressions in if statements | ![]() |
| x^2 | x squared |
| Incrementing | count +=1 |
modulus a % b |
the remainder when a is divided by b |
| random number between 1 and 20 | import random number=random.randint(1,20) |
| import a library (eg turtle) | from turtle import * |
| Length of a string | len() |
| Get a single character eg the 5th char | mystring[4] |
| Get the last character | mystring[-1] |
| Get a piece of a string | mystring[6:9] |
| Get an exact copy of a string | mystring[:] |
| Get the first 5 chars of a string | mystring[:5] |
Change to upper/lower case
|
mystring.upper() mystring.lower() |
| First or last letter alphabetically in a string | min(mystring) max(mystring) |
| Other string commands | ![]() |
| List of built in functions | http://docs.python.org/library/functions.html |






