Python Flashcards

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
Q

.

A

Dot self.x = 10

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

==

A

Equal
4 == 5 == False

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

*

A

Multiplication 2 * 4 == 8

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

/

A

Division 2 / 4 == 0.5

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

<

A

Less than
4 < 4 == False

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

>

A

Greater than 4 > 4 == False

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

del

A

Delete from dictionary.
del X[Y]

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

except

A

If an exception happens, do this.
except ValueError as e: print(e)

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

in

A

Part of for-loops. Also a test of X in Y.
for X in Y: pass also 1 in [1] == True

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

or

A

Logical or.
True or False == True

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

class

A

class Person(object)

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

as

A

Part of the with-as statement.
with X as Y: pass

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

return

A

Exit the function with a return value.
def X(): return Y

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

print

A

Print this string.
print(‘this string’)

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

lambda

A

Create a short anonymous function.
s = lambda y: y ** y; s(3)

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

with

A

yield Pause here and return to caller.
def X(): yield Y; X().next()

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

def

A

Define a function.
def X(): pass

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

if

A

If condition. if: X; elif: Y; else: J

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

exec

A

Run a string as Python.
exec ‘print(“hello”)’

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

import

A

Import a module into this one to use. import os

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

global

A

Declare that you want a global variable. global X

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

else

A

Else condition. if: X; elif: Y; else: J

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

pass

A

This block is empty.
def empty(): pass

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

from

A

Importing specific parts of a module.
from x import Y

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

assert

A

Assert (ensure) that something is true.
assert False, “Error!”

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

try

A

Try this block, and if exception, go to except.
try: pass

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

elif

A

Else if condition.
if: X; elif: Y; else: J

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

class

A

Define a class.
class Person(object)

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

is

A

Like == to test equality.
1 is 1 == True

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

and

A

Logical and.
True and False == False

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

for

A

Loop over a collection of things.
for X in Y: pass

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

finally

A

Exceptions or not, finally do this no matter what.
finally: pass

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

while

A

While loop.
while X: pass

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

break

A

Stop this loop right now.
while True: break

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

raise

A

Raise an exception when things go wrong.
raise ValueError(“No”)

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

not

A

Logical not.
not True == False

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

FALSE

A

False boolean value.
False and True == False

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

TRUE

A

True boolean value.
True or False == True

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

bytes

A

Stores bytes, maybe of text, PNG, file, etc.
x = b”hello”

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

lists

A

Stores a list of things.
j = [1,2,3,4]

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

strings

A

Stores textual information.
x = “hello”

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

dicts

A

Stores a key=value mapping of things.
e = {‘x’: 1, ‘y’: 2}

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

floats

A

Stores decimals.
i = 10.389

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

None

A

Represents ”nothing” or ”no value”.
x = None

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

numbers

A

Stores integers.
i = 100

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

def

A

How you define a function inside a class.

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

has-a

A

A phrase to say that something is composed of other things or has a trait, as in ”a salmon has-a mouth.”

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

attribute

A

A property classes have that are from composition and are usually variables.

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

instance

A

What you get when you tell Python to create a class

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

object

A

Two meanings: the most basic type of thing, and any instance of some thing

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

inheritance

A

The concept that one class can inherit traits from another class, much like you and your parents

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

class

A

Tell Python to make a new type of thing.

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

self

A

Inside the functions in a class, self is a variable for the instance/object being accessed

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

composition

A

The concept that a class can be composed of other classes as parts, much like how a car has wheels.

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

is-a

A

A phrase to say that something inherits from another, as in a ”salmon” is-a ”fish.”

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

Saltar

A

To jump

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

Los zapatos

A

Shoes

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

La biblioteca

A

The library

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

Lugares

A

Places

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

La cara

A

The face

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

Sentirse

A

To feel

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

Delante de

A

In front of

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

Soleado

A

Sunny

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

Cansado/a

A

Tired

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

Está tormentoso

A

It is stormy

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

Hay viento

A

It is windy

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

Sigue derecho

A

Go straight

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

Las indicaciones

A

Directions

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

La tortuga

A

The turtle

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

El correo

A

The post office

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

La oveja

A

The sheep

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

La camiseta

A

T-shirt

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

Luego

A

Then

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

La escuela

A

The school

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

El centro comercial

A

Shopping mall

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

El bolso

A

Purse/Bag

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

¿Qué tiempo hace hoy?

A

What is the weather like today?

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

Entre

A

Between

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

La espalda

A

The back

104
Q

Emociones

A

Emotions

105
Q

El tigre

A

The tiger

106
Q

El supermercado

A

The supermarket

107
Q

Confundido/a

A

Confused

108
Q

Los pantalones

A

Pants

109
Q

La ropa interior

A

Underwear

110
Q

El trueno

A

The thunder

111
Q

El pecho

A

The chest

112
Q

Cruzar

A

Cross

113
Q

Feliz

A

Happy

114
Q

Las manos

A

The hands

115
Q

Estación de autobús

A

Bus station

116
Q

Avergonzado/a

A

Embarrassed

117
Q

El cuerpo

A

The body

118
Q

Enamorado/a

A

In love

119
Q

Nublado

A

Cloudy

120
Q

A la derecha de

A

To the right of

121
Q

El otoño

A

Autumn/Fall

122
Q

Hace mal tiempo

A

The weather is bad

123
Q

La lluvia

A

The rain

124
Q

El elefante

A

The elephant

125
Q

El calcetín

A

Sock

126
Q

¿Cómo está el clima hoy?

A

How is the weather today?

127
Q

La cadera

A

The hip

128
Q

Incómodo/a

A

Uncomfortable

129
Q

El invierno

A

Winter

130
Q

Los dientes

A

The teeth

131
Q

La corbata

A

Tie

132
Q

Los brazos

A

The arms

133
Q

El edificio

A

The building

134
Q

Caminar

A

To walk

135
Q

El clima

A

The weather

136
Q

Las nubes

A

The clouds

137
Q

El caballo

A

The horse

138
Q

Las botas

A

Boots

139
Q

La luna

A

The moon

140
Q

La ropa

A

Clothing

141
Q

El traje de baño

A

Swimsuit

142
Q

La vaca

A

The cow

143
Q

Enojado/a

A

Angry

144
Q

Despacio

A

Slow

145
Q

Triste

A

Sad

146
Q

La muñeca

A

The wrist

147
Q

¿Dónde está…?

A

Where is…?

148
Q

Hace sol

A

It is sunny

149
Q

Los ojos

A

The eyes

150
Q

Ansioso/a

A

Anxious

151
Q

La falda

A

Skirt

152
Q

La iglesia

A

The church

153
Q

Enfadado/a

A

Angry

154
Q

La tormenta

A

The storm

155
Q

Las orejas

A

The ears

156
Q

Probar

A

To try on

157
Q

El cine

A

The cinema

158
Q

Emocionado/a

A

Excited

159
Q

El suéter

A

Sweater

160
Q

La oficina

A

The office

161
Q

Asustado/a

A

Scared

162
Q

La nieve

A

The snow

163
Q

La primavera

A

Spring

164
Q

Los dedos de pies

A

The toes

165
Q

La corbata

A

Tie

166
Q

Estación de tren

A

Train station

167
Q

El verano

A

Summer

168
Q

La blusa

A

La blusa

169
Q

Hace calor

A

It is hot

170
Q

El vestido

A

Dress

171
Q

El traje

A

Suit

172
Q

Detrás de

A

Behind

173
Q

Tímido/a

A

Shy

174
Q

Girar

A

Turn

175
Q

Hace frío

A

It is cold

176
Q

Los pantalones cortos

A

Shorts

177
Q

Los pies

A

The feet

178
Q

Los animales

A

The animals

179
Q

La camisa

A

Shirt

180
Q

La esquina

A

The corner

181
Q

El restaurante

A

The restaurant

182
Q

El parque

A

The park

183
Q

El gato

A

The cat

184
Q

Aburrido/a

A

Bored

185
Q

El cerdo

A

The pig

186
Q

¿Adónde vas?

A

Where are you going?

187
Q

Ir de compras

A

To go shopping

188
Q

El sombrero

A

Hat

189
Q

El león

A

The lion

190
Q

El perro

A

The dog

191
Q

Los dedos

A

The fingers

192
Q

El cinturón

A

Belt

193
Q

Sorprendido/a

A

Surprised

194
Q

El sol

A

The sun

195
Q

Nervioso/a

A

Nervous

196
Q

Rápido

A

Fast

197
Q

El abrigo

A

Coat

198
Q

El pájaro

A

The bird

199
Q

El tobillo

A

The ankle

200
Q

El hombro

A

The shoulder

201
Q

A la izquierda de

A

To the left of

202
Q

Está nevando

A

It is snowing

203
Q

Tocar

A

To touch

204
Q

La cabeza

A

The head

205
Q

Las zapatillas

A

Sneakers

206
Q

A lado de

A

Next to

207
Q

El pato

A

The duck

208
Q

La rodilla

A

The knee

209
Q

El pelo

A

The hair

210
Q

Frustrado/a

A

Frustrated

211
Q

Hace buen tiempo

A

The weather is nice

212
Q

El codo

A

The elbow

213
Q

La playa

A

The beach

214
Q

Preocupado/a

A

Worried

215
Q

Primero

A

First

216
Q

En frente

A

In front

217
Q

Correr

A

To run

218
Q

Está lluvioso

A

It is rainy

219
Q

Cómodo/a

A

Comfortable

220
Q

El oso

A

The bear

221
Q

El cabello

A

The hair (on head)

222
Q

El relámpago

A

The lightning

223
Q

La tienda

A

The store

224
Q

Las piernas

A

The legs

225
Q

El toro

A

The bull

226
Q

El estómago

A

The stomach

227
Q

\

A

Backslash

228
Q

"

A

Double-quote

229
Q

\a

A

Bell

230
Q

\r

A

Carriage

231
Q

\b

A

Backspace

232
Q

\f

A

Formfeed

233
Q

\b

A

Backspace

234
Q

\t

A

Tab

235
Q

'

A

Single-quote

236
Q

\v

A

Vertical tab

237
Q

\n

A

Newline

238
Q

class X(object): def M(self, J) ”

A

”class X has-a function named M that takes self and J parameters.”

239
Q

foo = X() ”

A

”Set foo to an instance of class X.”

240
Q

foo.M(J)

A

”From foo, get the M function, and call it with parameters self, J.”

241
Q

class X(Y) ”

A

”Make a class named X that is-a Y.”

242
Q

foo.K = Q

A

”From foo, get the K attribute, and set it to Q.”

243
Q

class X(object): def __init__(self, J)

A

”class X has-a __init__ that takes self and J parameters.”

244
Q

List

A

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
Q

Dictionary
Looping

A

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
Q

Adding
elements

A

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
Q

Set

A

A set is an unordered collection of unique
elements (“at-most-once”).

basket = { ‘apple’ , ‘eggs’ , ‘banana’ , ‘orange’ }
same = set([ ‘apple’ , ‘eggs’ , ‘banana’ , ‘orange’] )

248
Q

Reversing

A

This reverses the order of list elements.

[ 1 , 2 , 3 ].reverse() # [3, 2, 1]

249
Q

Sorting

A

Sorts a list. The computational complexity
of sorting is linear in the no. list elements.

[ 2 , 4 , 2 ].sort() # [2, 2, 4]

250
Q

Stack

A

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
Q

Reading and
writing
elements

A

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
Q

Membership
operator

A

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
Q

Indexing

A

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
Q

Removal

A

Removing an element can be slower.

[ 1 , 2 , 2 , 4 ].remove( 1 ) # [2, 2, 4]

255
Q

Dictionary

A

The dictionary is a useful data structure for
storing (key, value) pairs.

calories = { ‘apple’ : 52 , ‘banana’ : 89 , ‘choco’ : 546 }