You are on page 1of 2

Python

##declaring variables
var = 7
var = 1.23
var = 'das'
var = "dad"
var = True
var = False
contiuning on next line -> \
##Comments
#inline comment
"""
block comment
"""
''' also works'''
##math
+ - * /
** %
##printing
print var
print ("%.2f" %var)
print var + "qwerty"
print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)
name = raw_input("What is your name?")
#strings
escape char \
fifth_letter = "MONTY"[4]
len()
.lower() #only on strings
.upper()
str() $turns non strings into strings
.isalpha()
#access parts of strings
stringlist = stringlist[1:]
stringlist = stringlist[:4}
#importing library
from lib import method
from datetime import datetime
now = datetime.now()
print now.year
print now.month
print now.day
import math
> need to use math.function() #generic import
from module import function
from module import * #universal import
dir(math) #list of functions from math
## define function
def function(arg):
#needs a tab
#do stuff
return ifnecessary

not > and > or


if elif else
#multiple arguments
def biggest_number(*args):
print max(args)
return max(args)

You might also like