Python Flashcards

1
Q

The language’s name isn’t about snakes, but about the popular British comedy troupe ___ (from the 1970s).

A

Monty Python

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

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.

A

Guido Van Rossum

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

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”)

A

B. if 5 > 3: print(greater); print (lesser)

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

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.”’)

A

E. print(‘“Greg’s book.”’)

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

You need a colon at the end of every block of code in Python.

true or false?

A

false

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

Which shortcut key is used to quickly comment or uncomment multiple lines of code?

A

CTRL + /

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

Which of the following names are illegal in Python?

enumerate 3

A
  • starting with a number
  • has space
  • not descriptive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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)

A

8.0

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

This method adds an element at a given position in the list.

A

insert()

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

Which version of Python uses ordered dictionaries?

A

Version 3.7

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

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”)

A

one
two

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

Which logical operator is used to check if at least one of two conditions is True?

A

or

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

With list comprehension you will have to write a for statement with a conditional test inside.

true or false?

A

false

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

Which shortcut key is used to terminate your program in an infinite loop?

A

CTRL + C

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

The ____ keyword catches anything which isn’t caught by the preceding conditions.

A

else

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

What is the output of the following snippet?

for i in range(0, 6, 3):
print(i, end=” “)

A

0 3

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

What is the output of the following snippet?

n = 3

while n>0:
print(n+1, end=”:”)
n -= 1
else:
print(n)

A

4:3:2:0

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

How do you check the current installed version of Python in your system? (what to type in the command prompt)

A

python –version

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

This acts as a placeholder in for loops.

A

pass

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

If the condition is False

 * the code inside \_\_\_\_ keyword is executed 

 * the code inside \_\_\_\_ keyword is skipped

answer, answer

A

else, if

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

What is the output of the following snippet?

print(“String #1”)
print(“String #2)

A

String #2

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

What keyword is Python’s way of saying “if the previous condition were not true, then try this condition”?

A

elif

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

What is the output of the following snippet?

This is
a multiline
comment. #

print(“Hello!”)

A

Syntax Error: invalid syntax

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

What is the expected output of the following snippet?

print((2*4.), (2%4), (2**3))

A

8, 2, 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
This mode appends to a file and creates the file if it does not exist or overwrites an existing file.
a
26
The attributes inside the class is called _____
variables
27
What is the correct syntax of printing all variables and function names of a module?
dir
28
These arguments allow you to pass multiple non-key arguments.
arbitrary
29
A package in python is a container that contains various functions to perform specific tasks. | true or false?
true
30
A user-defined blueprint or prototype from which objects are created. *
class
31
Which of the following is a valid lambda function in Python? A. lambda x: x * 2, y B. lambda (x, y): x + y C. lambda x, y: x + y D. lambda x y: x + y
C. lambda x, y: x + y
32
To delete a file, you must import the OS module, and run its_______
os.remove()
33
What is python’s package manager?
pip
34
This type of polymorphism is used in dynamic languages such as Python, Perl, Ruby, PHP, and Javascript.
duck typing
35
How many types of __init__() constructor are there based on the report?
3
36
What is the correct syntax of importing only a specific function or variable?
from
37
The “___” method will overwrite the entire file.
w
38
True or False: Derived class is the other term for the Parent class and Base class is the other term for Child Class. | true or false?
false
39
Which keyword is used to define a lambda function in Python?
lambda
40
Can a lambda function have multiple expressions?
No, it can only have a single expression.
41
What do you call a function in inheritance that makes the child inherit all the properties from its source?
super() function
42
What package is installed to send http requests to APIs?
requests
43
To delete an entire folder, use the ______
os.rmdir()
44
In child class, we use this instead of pass. What do you call this function?
__init__() function
45
To define a function, you need to type _____ followed by a unique function name.
def
46
To write to an existing file, you must add a parameter to the _______ function:
open()
47
In order to overload operators, you must define their corresponding special methods in your class. | true or false?
true
48
What is the built-in function to open a file in Python?
open()
49
It is a good practice to always _________ the file when you are done with it.
close()
50
This type of polymorphism needs to have at least two classes.
Method Overriding
51
In Python, you can return one line in a file by using the _________ method:
readline()
52
When combining positional arguments and keyword arguments, you must put _______ arguments first.
positional
53
The os.remove module can remove a file or file path but cannot delete a directory. | true or false?
true
54
remove all elements from the dictionary
clear()
55
returns a copy of the dictionary
copy()
56
returns a dictionary with the specified keys and value
fromkeys()
57
returns the value of the specified key
get()
58
returns a list containing a tuple for each key value pair
items()
59
returns a list containing the dictionary's keys
keys()
60
removes the element with the specified key
pop()
61
removes the last inserted key-value pair
popitem()
62
returns value of specified key; if key does not exist: insert the key with the specified value
setdefault()
63
updates dictionary with the specified key-value pairs
update()
64
returns a list of all values in the dictionary
values()
65
mechanism that allows you to create a hierarchy of classes that share a set of properties and methods by deriving a class from another class.
inheritance
66
With inheritance, there are two classes that we need to take note of:
1. **Parent Class or Base Class** - the class being inherited from 2. **Child Class or Derived Class** - the class that inherits from another class
67
most basic form of inheritance, wherein the child inherits from a single parent
Single Inheritance
68
occurs when there are two or more parent classes from which a child class may inherit.
Multiple Inheritance
69
the ability for a child class to be the parent class of another. Thus, to stretch the analogy, we have a grandparent, parent, child relationship that describes multilevel inheritance.
Multilevel Inheritance
70
resembles the classic hierarchical structure of an organisation tree. It has a parent with multiple children.
Hierarchical Inheritance
71
is simply an amalgam of the other types of inheritance
Hybrid Inheritance
72
Python also has the ___ function that will make the child class inherit all the methods and properties from its parent
super()