The Python Tutorial: Chapter 3 - An Informal Introduction to Python Flashcards
What is the operator sign for doing floor division in Python?
What is floor division
It is //
Floor division is only returning whole integers without the remainder when dividing
What is the last result saved as in the Python Interpreter? i.e. what is the symbol for it?
It’s an underscore and can be used as a throwaway variable
How do you use raw strings? i.e. ignore the \ which typically indicates a special character?
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 do you concatenate two strings without a comma or a plus sign?
Just put them next to each other, they are automatically concatenated.
E.g.
»> ‘Py’ ‘thon’
‘Python’
When slicing, is the start included or excluded? What about the end?
Beginning is included and the end is excluded so that
s[:i] + s[i:] is always equal to s:
Give an example of multiple assignment
>>> # Fibonacci series: ... # the sum of two elements defines the next ... a, b = 0, 1 >>> while a < 10: ... print(a) ... a, b = b, a+b
What does the keyword argument ‘end’ do in the print function?
End can specify what is used to separate results when printing. The default is a newline.
E.g.
print(a, end=’,’)