Keywords Flashcards

1
Q

and

A

Logical and.

True and False == False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
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
3
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
4
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
5
Q

class

A

Define a class.

class Person(object)

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

continue

A

Don’t process more of the loop, do it again.

while True: continue

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

def

A

Define a function.

def X(): pass

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

del

A

Delete from dictionary.

del X[Y]

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

except

A

If an exception happens, do this.

except ValueError, e: print e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
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
11
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
12
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
13
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
14
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
15
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
16
Q

lambda

A

Create a short anonymous function.

s = lambda y: y ** y; s(3)

17
Q

not

A

Logical not.

not True == False

18
Q

or

A

Logical or.

True or False == True

19
Q

raise

A

Raise an exception when things go wrong.

raise ValueError(“No”)

20
Q

with

A

With an expression as a variable do.

with X as Y: pass

21
Q

yield

A

Pause here and return to caller.

def X(): yield Y; X().next()

22
Q

dicts

A

Stores a key=value mapping of things.

e = {‘x’: 1, ‘y’: 2}

23
Q

lists

A

Stores a list of things.

j = [1,2,3,4]