Python Flashcards
What is snake case in python?
Using underscores to form a long variable name
What is the type of the result of a division operation in python?
floating point
How do you get integer value out out of a division in python?
By using the ‘//’ operator
Does // operator do a round-off?
No
How do you distinguish between a variable definition and further use in python?
You can’t, both have same syntax
f-strings are available from which python version?
3.6 onwards.
What are f-strings?
A convenient way to format different types into string
What is another way (than f-strings) to format strings without explicitly converting them?
By having placeholders in the string with “{}” and calling the format method of the string with requisite parameters
What is the constraint on the number of parameters for the format method of the string?
It can be more, but cannot be less
In what ways “format” can take parameters for a string?
format can take parameters as positional as well as keyword based.
How does “format” method take keyword based arguments?
keyword based arguments have to be given in the last after positional arguments. They cannot be mixed.
What is necessary for passing keyword based arguments to “format” method of string?
The string should contain the keyword in { } in it
Is string.format(name=name) valid? Both identifiers
Yes, the first one will be looked for in the string, while the second one is treated as a proper variable
How does f-string and format compare?
- f-string takes actual parameters, while format takes formal parameters (which is to be filled in by passing format with actual parameters)
- f-string can take expressions that evaluate to a value, while format cannot
Which function in python reads input from keyboard and returns a string?
input(“message”)
What are boolean keywords in python?
True and False
What does print take?
An expression that can be evaluated
What are python’s boolean operators?
and, not, or
What does and/or return?
- and returns first value if it is false, otherwise it returns the second value
- or returns the first value it is true, otherwise it returns the second value
What does not return?
not always returns True or False
What does list.remove() take?
The value of the element which needs to be removed from the list
Is parens mandatory for writing tuples?
No
How to minimally express a tuple of only one item?
a,
How do you add a new element to a tuple variable?
By adding “+” another tuple of single element to the variable: v = v + (e,)