Python Flashcards

(255 cards)

1
Q

Front_Card

A

Back_Card

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

-

A

Subtraction 2 - 4 == -2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

/=

A

Divide and assign x = 1; x /= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

@

A

At (decorators)
@classmethod

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

*=

A

Multiply and assign x = 1; x *= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

**

A

Power of 2 ** 4 == 16

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

%

A

String interpolate or modulus
2 % 4 == 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

:

A

Colon def
X():

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

+

A

Addition
2 + 4 == 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

> =

A

Greater than equal
4 >= 4 == True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

<=

A

Less Than equal
4 <= 4 == True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

[ ]

A

List brackets
[1,3,4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

-=

A

Subtract and assign x = 1; x -= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

+=

A

Add and assign
x = 1; x += 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

=

A

; semi-colon print(“hi”); print(“there”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

**=

A

Power assign x = 1; x **= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

{ }

A

Dict curly braces
{‘x’: 5, ‘y’: 10}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

//=

A

Floor divide and assign
x = 1; x //= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

*=

A

Multiply and assign x = 1; x *= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

( )

A

Parenthesis
len(‘hi’) == 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

!=

A

Not equal
4 != 5 == True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

%=

A

Modulus assign
x = 1; x %= 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

,

A

Comma range(0, 10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

//

A

Floor division 2 // 4 == 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
.
Dot self.x = 10
26
==
Equal 4 == 5 == False
27
*
Multiplication 2 * 4 == 8
28
/
Division 2 / 4 == 0.5
29
<
Less than 4 < 4 == False
30
>
Greater than 4 > 4 == False
31
del
Delete from dictionary. del X[Y]
32
except
If an exception happens, do this. except ValueError as e: print(e)
33
in
Part of for-loops. Also a test of X in Y. for X in Y: pass also 1 in [1] == True
34
or
Logical or. True or False == True
35
class
class Person(object)
36
as
Part of the with-as statement. with X as Y: pass
37
return
Exit the function with a return value. def X(): return Y
38
print
Print this string. print('this string')
39
lambda
Create a short anonymous function. s = lambda y: y ** y; s(3)
40
with
yield Pause here and return to caller. def X(): yield Y; X().next()
41
def
Define a function. def X(): pass
42
if
If condition. if: X; elif: Y; else: J
43
exec
Run a string as Python. exec 'print("hello")'
44
import
Import a module into this one to use. import os
45
global
Declare that you want a global variable. global X
46
else
Else condition. if: X; elif: Y; else: J
47
pass
This block is empty. def empty(): pass
48
from
Importing specific parts of a module. from x import Y
49
assert
Assert (ensure) that something is true. assert False, "Error!"
50
try
Try this block, and if exception, go to except. try: pass
51
elif
Else if condition. if: X; elif: Y; else: J
52
class
Define a class. class Person(object)
53
is
Like == to test equality. 1 is 1 == True
54
and
Logical and. True and False == False
55
for
Loop over a collection of things. for X in Y: pass
56
finally
Exceptions or not, finally do this no matter what. finally: pass
57
while
While loop. while X: pass
58
break
Stop this loop right now. while True: break
59
raise
Raise an exception when things go wrong. raise ValueError("No")
60
not
Logical not. not True == False
61
FALSE
False boolean value. False and True == False
62
TRUE
True boolean value. True or False == True
63
bytes
Stores bytes, maybe of text, PNG, file, etc. x = b"hello"
64
lists
Stores a list of things. j = [1,2,3,4]
65
strings
Stores textual information. x = "hello"
66
dicts
Stores a key=value mapping of things. e = {'x': 1, 'y': 2}
67
floats
Stores decimals. i = 10.389
68
None
Represents ”nothing” or ”no value”. x = None
69
numbers
Stores integers. i = 100
70
def
How you define a function inside a class.
71
has-a
A phrase to say that something is composed of other things or has a trait, as in ”a salmon has-a mouth.”
72
attribute
A property classes have that are from composition and are usually variables.
73
instance
What you get when you tell Python to create a class
74
object
Two meanings: the most basic type of thing, and any instance of some thing
75
inheritance
The concept that one class can inherit traits from another class, much like you and your parents
76
class
Tell Python to make a new type of thing.
77
self
Inside the functions in a class, self is a variable for the instance/object being accessed
78
composition
The concept that a class can be composed of other classes as parts, much like how a car has wheels.
79
is-a
A phrase to say that something inherits from another, as in a ”salmon” is-a ”fish.”
80
Saltar
To jump
81
Los zapatos
Shoes
82
La biblioteca
The library
83
Lugares
Places
84
La cara
The face
85
Sentirse
To feel
86
Delante de
In front of
87
Soleado
Sunny
88
Cansado/a
Tired
89
Está tormentoso
It is stormy
90
Hay viento
It is windy
91
Sigue derecho
Go straight
92
Las indicaciones
Directions
93
La tortuga
The turtle
94
El correo
The post office
95
La oveja
The sheep
96
La camiseta
T-shirt
97
Luego
Then
98
La escuela
The school
99
El centro comercial
Shopping mall
100
El bolso
Purse/Bag
101
¿Qué tiempo hace hoy?
What is the weather like today?
102
Entre
Between
103
La espalda
The back
104
Emociones
Emotions
105
El tigre
The tiger
106
El supermercado
The supermarket
107
Confundido/a
Confused
108
Los pantalones
Pants
109
La ropa interior
Underwear
110
El trueno
The thunder
111
El pecho
The chest
112
Cruzar
Cross
113
Feliz
Happy
114
Las manos
The hands
115
Estación de autobús
Bus station
116
Avergonzado/a
Embarrassed
117
El cuerpo
The body
118
Enamorado/a
In love
119
Nublado
Cloudy
120
A la derecha de
To the right of
121
El otoño
Autumn/Fall
122
Hace mal tiempo
The weather is bad
123
La lluvia
The rain
124
El elefante
The elephant
125
El calcetín
Sock
126
¿Cómo está el clima hoy?
How is the weather today?
127
La cadera
The hip
128
Incómodo/a
Uncomfortable
129
El invierno
Winter
130
Los dientes
The teeth
131
La corbata
Tie
132
Los brazos
The arms
133
El edificio
The building
134
Caminar
To walk
135
El clima
The weather
136
Las nubes
The clouds
137
El caballo
The horse
138
Las botas
Boots
139
La luna
The moon
140
La ropa
Clothing
141
El traje de baño
Swimsuit
142
La vaca
The cow
143
Enojado/a
Angry
144
Despacio
Slow
145
Triste
Sad
146
La muñeca
The wrist
147
¿Dónde está…?
Where is…?
148
Hace sol
It is sunny
149
Los ojos
The eyes
150
Ansioso/a
Anxious
151
La falda
Skirt
152
La iglesia
The church
153
Enfadado/a
Angry
154
La tormenta
The storm
155
Las orejas
The ears
156
Probar
To try on
157
El cine
The cinema
158
Emocionado/a
Excited
159
El suéter
Sweater
160
La oficina
The office
161
Asustado/a
Scared
162
La nieve
The snow
163
La primavera
Spring
164
Los dedos de pies
The toes
165
La corbata
Tie
166
Estación de tren
Train station
167
El verano
Summer
168
La blusa
La blusa
169
Hace calor
It is hot
170
El vestido
Dress
171
El traje
Suit
172
Detrás de
Behind
173
Tímido/a
Shy
174
Girar
Turn
175
Hace frío
It is cold
176
Los pantalones cortos
Shorts
177
Los pies
The feet
178
Los animales
The animals
179
La camisa
Shirt
180
La esquina
The corner
181
El restaurante
The restaurant
182
El parque
The park
183
El gato
The cat
184
Aburrido/a
Bored
185
El cerdo
The pig
186
¿Adónde vas?
Where are you going?
187
Ir de compras
To go shopping
188
El sombrero
Hat
189
El león
The lion
190
El perro
The dog
191
Los dedos
The fingers
192
El cinturón
Belt
193
Sorprendido/a
Surprised
194
El sol
The sun
195
Nervioso/a
Nervous
196
Rápido
Fast
197
El abrigo
Coat
198
El pájaro
The bird
199
El tobillo
The ankle
200
El hombro
The shoulder
201
A la izquierda de
To the left of
202
Está nevando
It is snowing
203
Tocar
To touch
204
La cabeza
The head
205
Las zapatillas
Sneakers
206
A lado de
Next to
207
El pato
The duck
208
La rodilla
The knee
209
El pelo
The hair
210
Frustrado/a
Frustrated
211
Hace buen tiempo
The weather is nice
212
El codo
The elbow
213
La playa
The beach
214
Preocupado/a
Worried
215
Primero
First
216
En frente
In front
217
Correr
To run
218
Está lluvioso
It is rainy
219
Cómodo/a
Comfortable
220
El oso
The bear
221
El cabello
The hair (on head)
222
El relámpago
The lightning
223
La tienda
The store
224
Las piernas
The legs
225
El toro
The bull
226
El estómago
The stomach
227
\\
Backslash
228
\"
Double-quote
229
\a
Bell
230
\r
Carriage
231
\b
Backspace
232
\f
Formfeed
233
\b
Backspace
234
\t
Tab
235
\'
Single-quote
236
\v
Vertical tab
237
\n
Newline
238
class X(object): def M(self, J) ”
”class X has-a function named M that takes self and J parameters.”
239
foo = X() ”
”Set foo to an instance of class X.”
240
foo.M(J)
”From foo, get the M function, and call it with parameters self, J.”
241
class X(Y) ”
”Make a class named X that is-a Y.”
242
foo.K = Q
”From foo, get the K attribute, and set it to Q.”
243
class X(object): def __init__(self, J)
”class X has-a __init__ that takes self and J parameters.”
244
List
A container data type that stores a sequence of elements. Unlike strings, lists are mutable: modification possible. l = [ 1 , 2 , 2 ] print(len(l)) # 3
245
Dictionary Looping
You can access the (key, value) pairs of a dictionary with the items() method. for k, v in calories.items(): print(k) if v > 500 else None # 'chocolate'
246
Adding elements
Add elements to a list with (i) append, (ii) insert, or (iii) list concatenation. The append operation is very fast. [ 1 , 2 , 2 ].append( 4 ) # [1, 2, 2, 4] [ 1 , 2 , 4 ].insert( 2 , 2 ) # [1, 2, 2, 4] [ 1 , 2 , 2 ] + [ 4 ] # [1, 2, 2, 4]
247
Set
A set is an unordered collection of unique elements (“at-most-once”). basket = { 'apple' , 'eggs' , 'banana' , 'orange' } same = set([ 'apple' , 'eggs' , 'banana' , 'orange'] )
248
Reversing
This reverses the order of list elements. [ 1 , 2 , 3 ].reverse() # [3, 2, 1]
249
Sorting
Sorts a list. The computational complexity of sorting is linear in the no. list elements. [ 2 , 4 , 2 ].sort() # [2, 2, 4]
250
Stack
Python lists can be used intuitively as stacks via the two list operations append() and pop() stack = [3] stack.append( 42 ) # [3, 42] stack.pop() # 42 (stack: [3]) stack.pop() # 3 (stack: [] )
251
Reading and writing elements
Read and write elements by specifying the key within the brackets. Use the keys() and values() functions to access all keys and values of the dictionary. print(calories[ 'apple' ] < calories[ 'choco' ]) # True calories[ 'cappu' ] = 74 print(calories[ 'banana' ] < calories[ 'cappu' ]) # False print( 'apple' in calories.keys()) # True print( 52 in calories.values()) # True
252
Membership operator
Check with the ‘in’ keyword whether the set, list, or dictionary contains an element. Set containment is faster than list containment. basket = { 'apple' , 'eggs' , 'banana' , 'orange' } print( 'eggs' in basket) # True print( 'mushroom' in basket) # False
253
Indexing
Finds the first occurence of an element in the list & returns its index. Can be slow as the whole list is traversed [ 2 , 2 , 4 ].index( 2 ) # index of element 4 is "0" [ 2 , 2 , 4 ].index( 2 , 1 ) # index of element 2 after pos 1 is "1"
254
Removal
Removing an element can be slower. [ 1 , 2 , 2 , 4 ].remove( 1 ) # [2, 2, 4]
255
Dictionary
The dictionary is a useful data structure for storing (key, value) pairs. calories = { 'apple' : 52 , 'banana' : 89 , 'choco' : 546 }