python quiz Flashcards
Which one is NOT a legal variable name?
Myvar
my_var
my-var
_myvar
my-var
How do you create a variable with the numeric value 5?
Both the other answers are correct
x = 5
x = int(5)
Both the other answers are correct
What is a correct syntax to return the first character in a string?
x = “Hello”.sub(0, 1)
x = “Hello”[0]
x = sub(“Hello”, 0, 1)
x = “Hello”[0]
Which method can be used to remove any whitespace from both the beginning and the end of a string?
trim()
ptrim()
len()
strip()
strip()
Which method can be used to replace parts of a string?
switch()
replace()
replaceString()
repl()
replace()
Which collection does not allow duplicate members?
TUPLE
SET
LIST
SET
How do you start writing a while loop in Python?
while x > y {
while (x > y)
x > y while {
while x > y:
while x > y:
for x in y:
for each x in y:
for x > y:
for x in y:
Consider the following function definition:
def hello_name(name: str) -> str:
return f”Hello {name}”
What does the -> str part of the function definition indicate?
The function is expected to return a string.
Where are docstrings stored within a Python object?
In the .__doc__ property
What are the three major categories of docstrings in Python?
Class, method, and function docstrings
Package and module docstrings
Script docstrings
What are the recommended parts to include in the documentation of a private project?
A README and an examples.py file
What’s a good approach to structuring the docs/ folder of a public or open-source Python project?
Tutorials
How-To Guides
References
Explanations
How would you express the hexadecimal value a5 as a base-16 integer constant in Python?
0xa5
How would you express the constant floating-point value 3.2 × 10-12 in Python:
3.2e-12