Python Augmented Assignment Flashcards

 

card 1 of 11

 

>>> x = "Iowa"
>>> x *= 3
>>> x

 

an assignment like 'i *= 5' is shorthand for 'i = i * 5'

'IowaIowaIowa'

card 2 of 11

 

>>> R = 10.5
>>> R /= 2.0
>>> R

 

an assignment like 'i /= 2.0' is shorthand for 'i = i / 2.0'

5.25

card 3 of 11

 

>>> xT = 21
>>> xT -= 1
>>> xT

 

an assignment like 'i -= 2' is shorthand for 'i = i - 2'

20

card 4 of 11

 

>>> varK = [15,5,10,4]
>>> varK += 18
>>> varK

 

an assignment like 'i += 2' is shorthand for 'i = i + 2'

TypeError: concatenation of a list needs a list

card 5 of 11

 

>>> varK = [15,5,10,4]
>>> varK += [18]
>>> varK

 

an assignment like 'i += 2' is shorthand for 'i = i + 2'

[15,5,10,4,18]

card 6 of 11

 

>>> memo = "how did we get"
>>> memo += "here"
>>> memo

 

an assignment like 'i += 2' is shorthand for 'i = i + 2'

'how did we gethere'

card 7 of 11

 

>>> axis, roll = "X in inches", "datagram size"
>>> axis += ' ' + roll
>>> axis

 

evaluate right side first before assignment

'X in inches datagram size'

card 8 of 11

 

>>> N, y = 50, 3
>>> N += 8*y
>>> N

 

remember operator priorities in evaluation

74

card 9 of 11

 

>>> Accum = [ True, [ ], 1 ]
>>> Accum += "off"
>>> Accum

 

strings can behave like lists of characters

[True, [ ], 1, 'o', 'f', 'f']

card 10 of 11

 

>>> III = [True]
>>> III += III
>>> III += III
>>> III

 

in each case, evaluate right side first before assignment

[True,True,True,True]

card 11 of 11

 

>>> i = 99
>>> i++
>>> i

 

this one is easy

SyntaxError: Python is not Java or C!

 

End of Problem Set

(use browser reload to restart this problem set)