Symbols Flashcards
and
Logical and
Example:
True and False == False
as
Part of the with -as statement.
Example:
with X as Y: pass
assert
Assert (ensure) that something is true
Example:
assert False, “Error!”
break
stop this loop right now
Example:
While True: break
class
Define a class
Example:
class Person(object)
contiunue
Don’t process more of the loop, do it again.
Example:
while True: continue
def
Define a function
Example:
def X(): pass
del
Delete from a dictionary
Example:
del X(Y)
elif
Else if condition
Example:
if: X; elif: Y; else: J
else
Else condition
Example:
if: X; elif:: Y; else: J
except
If an exception happens, do this
Example:
except ValueError, e: print(e)
exec
Run a string as Python
Example:
|exec ‘print(“hello”) ‘
finally
Exceptions or not, finally do this no matter what
Example:
finally: pass
for
loop over a colletion of things
Example:
for X in Y: pass
from
Import specific parts of a module
Example:
from X import Y
global
Declare that you want a global variable
Example:
global X
if
If condition
Example:
if: X; elif: Y; else: J
import
Import a module into this one to use
Example:
import os
in
Part of for-loops.
Also a test of X in Y.
Example:
for X in Y: pass also 1 in (1) == True
is
Like == to test equality
Example:
1 is 1 == True
lambda
Create a short anonymous function
Example:
s = lambda y: y ** y; s(3)
not
Logical not
Example:
not True == False
or
Logical or
Example:
True or False == True
pass
This block is empty
Example:
def empty(): pass