Python Flashcards
Front_Card
Back_Card
-
Subtraction 2 - 4 == -2
/=
Divide and assign x = 1; x /= 2
@
At (decorators)
@classmethod
*=
Multiply and assign x = 1; x *= 2
**
Power of 2 ** 4 == 16
%
String interpolate or modulus
2 % 4 == 2
:
Colon def
X():
+
Addition
2 + 4 == 6
> =
Greater than equal
4 >= 4 == True
<=
Less Than equal
4 <= 4 == True
[ ]
List brackets
[1,3,4]
-=
Subtract and assign x = 1; x -= 2
+=
Add and assign
x = 1; x += 2
=
; semi-colon print(“hi”); print(“there”)
**=
Power assign x = 1; x **= 2
{ }
Dict curly braces
{‘x’: 5, ‘y’: 10}
//=
Floor divide and assign
x = 1; x //= 2
*=
Multiply and assign x = 1; x *= 2
( )
Parenthesis
len(‘hi’) == 2
!=
Not equal
4 != 5 == True
%=
Modulus assign
x = 1; x %= 2
,
Comma range(0, 10)
//
Floor division 2 // 4 == 0
.
Dot self.x = 10
==
Equal
4 == 5 == False
*
Multiplication 2 * 4 == 8
/
Division 2 / 4 == 0.5
<
Less than
4 < 4 == False
>
Greater than 4 > 4 == False
del
Delete from dictionary.
del X[Y]
except
If an exception happens, do this.
except ValueError as e: print(e)
in
Part of for-loops. Also a test of X in Y.
for X in Y: pass also 1 in [1] == True
or
Logical or.
True or False == True
class
class Person(object)
as
Part of the with-as statement.
with X as Y: pass
return
Exit the function with a return value.
def X(): return Y
Print this string.
print(‘this string’)
lambda
Create a short anonymous function.
s = lambda y: y ** y; s(3)
with
yield Pause here and return to caller.
def X(): yield Y; X().next()
def
Define a function.
def X(): pass
if
If condition. if: X; elif: Y; else: J
exec
Run a string as Python.
exec ‘print(“hello”)’
import
Import a module into this one to use. import os
global
Declare that you want a global variable. global X
else
Else condition. if: X; elif: Y; else: J
pass
This block is empty.
def empty(): pass
from
Importing specific parts of a module.
from x import Y
assert
Assert (ensure) that something is true.
assert False, “Error!”
try
Try this block, and if exception, go to except.
try: pass
elif
Else if condition.
if: X; elif: Y; else: J
class
Define a class.
class Person(object)
is
Like == to test equality.
1 is 1 == True
and
Logical and.
True and False == False
for
Loop over a collection of things.
for X in Y: pass
finally
Exceptions or not, finally do this no matter what.
finally: pass
while
While loop.
while X: pass
break
Stop this loop right now.
while True: break
raise
Raise an exception when things go wrong.
raise ValueError(“No”)
not
Logical not.
not True == False
FALSE
False boolean value.
False and True == False
TRUE
True boolean value.
True or False == True
bytes
Stores bytes, maybe of text, PNG, file, etc.
x = b”hello”
lists
Stores a list of things.
j = [1,2,3,4]
strings
Stores textual information.
x = “hello”
dicts
Stores a key=value mapping of things.
e = {‘x’: 1, ‘y’: 2}
floats
Stores decimals.
i = 10.389
None
Represents ”nothing” or ”no value”.
x = None
numbers
Stores integers.
i = 100
def
How you define a function inside a class.
has-a
A phrase to say that something is composed of other things or has a trait, as in ”a salmon has-a mouth.”
attribute
A property classes have that are from composition and are usually variables.
instance
What you get when you tell Python to create a class
object
Two meanings: the most basic type of thing, and any instance of some thing
inheritance
The concept that one class can inherit traits from another class, much like you and your parents
class
Tell Python to make a new type of thing.
self
Inside the functions in a class, self is a variable for the instance/object being accessed
composition
The concept that a class can be composed of other classes as parts, much like how a car has wheels.
is-a
A phrase to say that something inherits from another, as in a ”salmon” is-a ”fish.”
Saltar
To jump
Los zapatos
Shoes
La biblioteca
The library
Lugares
Places
La cara
The face
Sentirse
To feel
Delante de
In front of
Soleado
Sunny
Cansado/a
Tired
Está tormentoso
It is stormy
Hay viento
It is windy
Sigue derecho
Go straight
Las indicaciones
Directions
La tortuga
The turtle
El correo
The post office
La oveja
The sheep
La camiseta
T-shirt
Luego
Then
La escuela
The school
El centro comercial
Shopping mall
El bolso
Purse/Bag
¿Qué tiempo hace hoy?
What is the weather like today?
Entre
Between