Keywords Flashcards
del
delete from dictionary
except
Debugging: If an exception happens, do this..ex: except ValueError as e: print(e)
exec
Run a string as python. ex: exec ‘print(“hello”)’
finally
exceptions or not, finally do this no matter what. ex: finally: pass
for
loop over a collection of things. ex: for i in row:
print(i)
from
import specific parts from a module from flask import Flask
global
make this a global variable
global x
if
if condition
if x < 9:
print(“x is less than 9”)
import
import a module
in
part of a for loop.
for word in phrase:
print(word)
is
Like == to test equality
1 is 1 == True
lambda
Create a short anonymous function.
s = lambda y: y ** y; (s)3
not
logical not
if word not in phrase:
print(“That is not in the phrase”)
not True == False
or
logical or
True or False == True
pass
Filler word. Used to create an empty suite or block. def word(): pass
print this out to the console or what have you.
print(“Hello world!”)
raise
raise an exception when things go wrong.
raise ValueError(“No”)
try
try this block and see if it raises an exception, if so go to except:
try:
pass
while
while loop
while x > 0:
if x % 2 == 0:
print(“even”)
with
with an expression as a variable do…
with x as y:
pass
yield
pause here and return to caller.
def X(): yield Y; X().next()