Python Flashcards
The language’s name isn’t about snakes, but about the popular British comedy troupe ___ (from the 1970s).
Monty Python
He is a Dutch programmer best known as the creator of the Python programming language, for which he was the “benevolent dictator for life” (BDFL) until he stepped down from the position on 12 July 2018.
Guido Van Rossum
Which of the following would result in an error?
A. num = 5
if num > 3: print(“greater”); print (“lesser”)
B. if 5 > 3: print(greater); print (lesser)
C. #if 5 > 3: print(greater); print (lesser)
D. if 5 > 3:
print(“greater”)
print (“lesser”)
B. if 5 > 3: print(greater); print (lesser)
Which of the following print() function invocations will cause a SyntaxError?
A. print(‘Greg\ ‘s book.’)
B. print(“‘Greg’s book.’”)
C. print(‘“Greg's book.”’)
D. print(“Greg's book.”)
E. print(‘“Greg’s book.”’)
E. print(‘“Greg’s book.”’)
You need a colon at the end of every block of code in Python.
true or false?
false
Which shortcut key is used to quickly comment or uncomment multiple lines of code?
CTRL + /
Which of the following names are illegal in Python?
enumerate 3
- starting with a number
- has space
- not descriptive
What is the output of the following snippet if the user enters two and four respectively?
x = int(input())
y = int(input())
x = x/y
y = y/x
print(y)
8.0
This method adds an element at a given position in the list.
insert()
Which version of Python uses ordered dictionaries?
Version 3.7
What is the output of the following snippet?
x = 1
y = 1.0
z = “1”
if x == y:
print(“one”)
if y == int(z):
print(“two”)
elif x == y:
print(“three”)
else:
print(“four”)
one
two
Which logical operator is used to check if at least one of two conditions is True?
or
With list comprehension you will have to write a for statement with a conditional test inside.
true or false?
false
Which shortcut key is used to terminate your program in an infinite loop?
CTRL + C
The ____ keyword catches anything which isn’t caught by the preceding conditions.
else
What is the output of the following snippet?
for i in range(0, 6, 3):
print(i, end=” “)
0 3
What is the output of the following snippet?
n = 3
while n>0:
print(n+1, end=”:”)
n -= 1
else:
print(n)
4:3:2:0
How do you check the current installed version of Python in your system? (what to type in the command prompt)
python –version
This acts as a placeholder in for loops.
pass
If the condition is False
* the code inside \_\_\_\_ keyword is executed * the code inside \_\_\_\_ keyword is skipped
answer, answer
else, if
What is the output of the following snippet?
print(“String #1”)
print(“String #2)
String #2
What keyword is Python’s way of saying “if the previous condition were not true, then try this condition”?
elif
What is the output of the following snippet?
This is
a multiline
comment. #
print(“Hello!”)
Syntax Error: invalid syntax
What is the expected output of the following snippet?
print((2*4.), (2%4), (2**3))
8, 2, 8
This mode appends to a file and creates the file if it does not exist or overwrites an existing file.
a
The attributes inside the class is called _____
variables
What is the correct syntax of printing all variables and function names of a module?
dir
These arguments allow you to pass multiple non-key arguments.
arbitrary