The Python Tutorial: Chapter 3 - An Informal Introduction to Python Flashcards

1
Q

What is the operator sign for doing floor division in Python?
What is floor division

A

It is //

Floor division is only returning whole integers without the remainder when dividing

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

What is the last result saved as in the Python Interpreter? i.e. what is the symbol for it?

A

It’s an underscore and can be used as a throwaway variable

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

How do you use raw strings? i.e. ignore the \ which typically indicates a special character?

A

Use r before the string, it stands for ‘raw string’
E.g.
»> print(‘C:\some\name’) # here \n means newline!
C:\some
ame
»> print(r’C:\some\name’) # note the r before the quote
C:\some\name

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

How do you concatenate two strings without a comma or a plus sign?

A

Just put them next to each other, they are automatically concatenated.
E.g.
»> ‘Py’ ‘thon’
‘Python’

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

When slicing, is the start included or excluded? What about the end?

A

Beginning is included and the end is excluded so that

s[:i] + s[i:] is always equal to s:

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

Give an example of multiple assignment

A
>>> # Fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
>>> while a < 10:
...     print(a)
...     a, b = b, a+b
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the keyword argument ‘end’ do in the print function?

A

End can specify what is used to separate results when printing. The default is a newline.
E.g.
print(a, end=’,’)

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