Variables Flashcards

1
Q

variable names:

A

A variable name must consist of only letters, digits, and/or underscores (_)

A variable name must start with a letter or an underscore

A variable name should not be a reserved word

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

“Reserved words” are:

A
and       del       from      not       while    
as        elif      global    or        with     
assert    else      if        pass      yield    
break     except    import    print              
class     exec      in        raise              
continue  finally   is        return             
def       for       lambda    try
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you think of a way to swap the values of two variables that does not need a third variable as a temporary storage? In the code block below, try to implement the swapping of the values of a and b without using a third variable.

A
a = 17
b = 23
print( "a =", a, "and b =", b )
a += b
b = a - b
a  = a -b
print( "a =", a, "and b =", b )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly