Show Menu
Cheatography

Exam #2 Cheat Sheet (DRAFT) by

python #2 cheat sheet for the exam

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Day 6

= called assignment operator
print(­"­3"+"4­") = 34
print(­4**2) = 16

Day 10

total = 0
set = {} --> sets can't have duplicates
set.add() --> add element
set.re­move() - remove element
set.up­dat­e(set2) --> adds from another set
set.un­ion­(set2) - combines 2 sets without dup
set.in­ter­sec­tio­n(set2) --> finds dups

For Loop Names

names = ['Bob', 'Kat', 'Ray']
for each_name in names:
\tab print(each_name)
--------------
Rob
Kat
Ray
 

Day 7

len(name) --> # of char
name.c­api­tal­ize() --> cap first letter
name.t­itle() --> cap first each word
name.u­pper() --> entire string cap
name.s­trip() --> removes lead/trail space
name.r­epl­ace­('','') --> 'with what' 'repla­cing'
intput() --> user input
name = "­Mar­y", name[0:3] = Mar

Day 11

dictionary = {'name': 'Mary'} --> key/value pairs
print(­dic­tio­nar­y['­name']) = Mary
dictio­nar­y['­age'] = 21 --> adds a new key/value pair to exist dic
list.a­ppe­nd(­dic­tio­nary) --> add dictio­naries to list
dictio­nar­y.pop(' ') --> remove a key/value

Function Multiple Paramater

def welcom(name,greeting):
\tab print(f'Hey, {name}. {greeting}.')
welcome('Liz, 'How\'s it?')
---------------
Hey, Liz. How's it?
 

Day 8

phrase.pa­rti­tion() = splits into three parts of " "
phrase.sp­lit(' ') = splits into as many words
tuple = () --> can't be changed
list = [] --> modified
list --> tuple name = list(t­uple)
name.a­ppend() = adds to end of list
name.r­emove() = removes from list
number = 2.3211 --> print(­f'{­num­ber­:.2f}') = 12.32

Day 14

def hello():
      print("hi')
hello()
------
hi

Day 14

def hello():
\tabprint("hi')
hello()
------
hi

Day 9

range(5) --> 5 char --> 1,2,3,4,5
range(1,6) --> 5 char --> 1,2,3,4,5
range(­1,7,2) --> 1,3,5
range(­6,0,-1) --> 6,5,3,­3,2,1
i = index/­eve­rything
\t = adds a tab before text