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
Q

This mode appends to a file and creates the file if it does not exist or overwrites an existing file.

A

a

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

The attributes inside the class is called _____

A

variables

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

What is the correct syntax of printing all variables and function names of a module?

A

dir

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

These arguments allow you to pass multiple non-key arguments.

A

arbitrary

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

A package in python is a container that contains various functions to perform specific tasks.

true or false?

A

true

30
Q

A user-defined blueprint or prototype from which objects are created.
*

A

class

31
Q

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

A

C. lambda x, y: x + y

32
Q

To delete a file, you must import the OS module, and run its_______

A

os.remove()

33
Q

What is python’s package manager?

A

pip

34
Q

This type of polymorphism is used in dynamic languages such as Python, Perl, Ruby, PHP, and Javascript.

A

duck typing

35
Q

How many types of __init__() constructor are there based on the report?

A

3

36
Q

What is the correct syntax of importing only a specific function or variable?

A

from

37
Q

The “___” method will overwrite the entire file.

A

w

38
Q

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?

A

false

39
Q

Which keyword is used to define a lambda function in Python?

A

lambda

40
Q

Can a lambda function have multiple expressions?

A

No, it can only have a single expression.

41
Q

What do you call a function in inheritance that makes the child inherit all the properties from its source?

A

super() function

42
Q

What package is installed to send http requests to APIs?

A

requests

43
Q

To delete an entire folder, use the ______

A

os.rmdir()

44
Q

In child class, we use this instead of pass. What do you call this function?

A

__init__() function

45
Q

To define a function, you need to type _____ followed by a unique function name.

A

def

46
Q

To write to an existing file, you must add a parameter to the _______ function:

A

open()

47
Q

In order to overload operators, you must define their corresponding special methods in your class.

true or false?

A

true

48
Q

What is the built-in function to open a file in Python?

A

open()

49
Q

It is a good practice to always _________ the file when you are done with it.

A

close()

50
Q

This type of polymorphism needs to have at least two classes.

A

Method Overriding

51
Q

In Python, you can return one line in a file by using the _________ method:

A

readline()

52
Q

When combining positional arguments and keyword arguments, you must put _______ arguments first.

A

positional

53
Q

The os.remove module can remove a file or file path but cannot delete a directory.

true or false?

A

true

54
Q

remove all elements from the dictionary

A

clear()

55
Q

returns a copy of the dictionary

A

copy()

56
Q

returns a dictionary with the specified keys and value

A

fromkeys()

57
Q

returns the value of the specified key

A

get()

58
Q

returns a list containing a tuple for each key value pair

A

items()

59
Q

returns a list containing the dictionary’s keys

A

keys()

60
Q

removes the element with the specified key

A

pop()

61
Q

removes the last inserted key-value pair

A

popitem()

62
Q

returns value of specified key; if key does not exist: insert the key with the specified value

A

setdefault()

63
Q

updates dictionary with the specified key-value pairs

A

update()

64
Q

returns a list of all values in the dictionary

A

values()

65
Q

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.

A

inheritance

66
Q

With inheritance, there are two classes that we need to take note of:

A
  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
Q

most basic form of inheritance, wherein the child inherits from a single parent

A

Single Inheritance

68
Q

occurs when there are two or more parent classes from which a child class may inherit.

A

Multiple Inheritance

69
Q

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.

A

Multilevel Inheritance

70
Q

resembles the classic hierarchical structure of an organisation tree. It has a parent with multiple children.

A

Hierarchical Inheritance

71
Q

is simply an amalgam of the other types of inheritance

A

Hybrid Inheritance

72
Q

Python also has the ___ function that will make the child class inherit all the methods and properties from its parent

A

super()