Python Exam Review Flashcards

1
Q

If an object’s reference count is 0, memory for that object is deallocated and marked for garbage collection. True of False

A

True

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

All of the are true of variable in python, except

Constructed of a name and value
Considered a data container
Declare their variable type before assigning a value or object
Used for easy reference in computations

A

Declare the variable type before assigning a value or object

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

The input function returns an object of what data type?

A

string

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

What is the preferred method for string formatting in python 3.6+?

A

f string

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

Converting a variable to a different type is NOT called type casting. True or False

A

False

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

What is the comparison operator to see if two objects are explicitly equal?

A

==

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

In python, (2**3) evaluates to?
6
8
6.0
8.0

A

8

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

In python, (18 % 7) evaluates to?
2.57
4.0
2
4

A

4

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

In python, (18//7) evaluates to?
4
4.0
2
2.0

A

2

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

If we give XOR True and True, it will return?

A

False

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

Taking a subsection of a string or list is called “slicing” True of False

A

True

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

Which is not the conditions in python?
-Usually use boolean values to evaluate conditions

  • The final else is typed with explicit condition
  • You can use as many conditions as you want
  • Start with an if, end with an else, and elif every condition in between
A

The final else is typed with explicit condition

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

What is the only mathematical operator we can use on two strings?

A

+ plus sign

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

What is the only mathematical operator we can do on a string and an int?
+
-
*
/

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

Which advance data structures have we not discussed?
Dictionary
Tuple
List
Queue

A

Queue

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

The inputs to a string or list slice are start, stop, step respectively True or False

A

True

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

What data type do we index on an int?
Dictionary
tuple
list
queue

A

List

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

What type of data do we index on a string?

dictionary
tuple
list
queue

A

dictionary

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

With list, we use del to delete an item based on value, and we use the.remove method to remove an item based on index
True or False

A

False

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

What variable type is var, if we assign var = “Hello World”

string
dictionary
list
tuple

A

Tuple

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

What is regarded as the lowest level source code?
Python
C#
Java
Machine Code

A

Machine Code

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

What is the default implementation type of python that we get from python.org
Cypthon
Jython
IronPyton
Phyton2

A

Cypthon

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

Python is best at low level programming?
True or False

A

False

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

In Pycharm, what do you usually configure for every new project?

Theme
Font
Interpreter
Enable zoom with mouse wheel

A

Interpreter

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

What is not a primitive data type in python?

string
integer
boolean
character

A

character

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

Complied languages are faster as first, but get slower with each thereafter
True or False

A

False

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

When comparing python3 with python2, which is not true of python3?

Formally replaced python2 in early 2020

Strings are stored as ASCII characters by default

Uses print(“hello”) instead of print “hello”

int / int = float, not rounded to a whole number (int)

A

Strings are stored as ASCII characters by default

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

Which of these is not and IDE we mentioned?

PyCharm
IntelliJ IDEA
Visual Studio Code
C#

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

In python you can start a comment with both # and ‘””

A

True

30
Q

True or False “Hello World!” is a complete string?

A

False

31
Q

What data type is var in var = 7
string
int
float
boolean

A

int

32
Q

What data type is var in var = “cat”?
string
int
float
boolean

A

string

33
Q

What data type is var in var =
string
int
float
boolean

A

float

34
Q

What data type is var in var = False?
string
int
float
boolean

A

boolean

35
Q

Loops are blocks of code that repeat logic as long as a condition is true

A

True

36
Q

Loops repeat the indented code block on each iteration

A

True

37
Q

How many numbers get printed?
3
7
9
None

A

9

38
Q

What will be printed?
5
0-4
0-5
0

A

0-4

39
Q

The print function always has to end with a new line character
True or False

A

False

40
Q

What gets printed?

cat
3
catdog73
error

A

error

41
Q

What gets printed?

David John Cooper Nick,
David,John,Cooper,Nick,
1,2,3,4
0,1,2,3,

A

0,1,2,3,

42
Q

Which loop cannot be an infinite loop?
for loop
while loop
nested loop
all of these loops can be infinite

A

all of these loops can be infinite

43
Q

The following prints and infinite loop
True or False
nums = [1, 2, 3]
for i in range (len(nums)):
print (i)
nums.append(i)

A

False

44
Q

The following prints and infinite loop
start = 0
while start < 4:
print(start)

A

True

45
Q

What does the following print?

word = “Sunshine”
for i in range(1, 7, 2 ):
print(word[i], end=”@”)

1@3@5@
u@s@i@
Sunshine@
u@s@i@e@

A

u@s@i@

46
Q

What will the following do?

password =””
while password != “Pa$$w0rd”:
password = input(“Enter password: “)

infinite loop
ask for password until Pa$$w0rd is entered
ask for password once
print the password

A

ask for password until Pa$$w0rd is entered

47
Q

What type of loop do we use if we don’t know how many times we want to repeat something?

while loop
for loop
nested loop
if function

A

while loop

48
Q

What 2 python keywords do we use in combination to handle errors?

try and except
try and else
try and error
except and finally

A

try and except

49
Q

Which method is the os module gets the path?
os.getcwd
os.walk
os.stat
os.listdir

A

os.getcwd

50
Q

Which is not NOT a common exception type we mentioned?

ZeroDivisionError
TypeError
KeyboardInterrupt
CombinationError

A

CombinationError

51
Q

What is the output of the following?
try:
num1 = 10
num2 = 0
div = num1 / num2
except ZerDivisionError:
print(“cat” , end=” “)
else:
print(“sat” , end=” “)
finally:
print(“mat” , end=” “)

cat
cat sat
cat mat
cat sat mat

A

cat mat

52
Q

What python keyword forcefully raises an exception every time?

except
raise
error
else

A
53
Q

The code inside a finally block only runs if the block is successful.
True or False

A

False

54
Q

What python keyword automatically close a file upon completion of its code block?
open
with open
flush
read

A

with open

55
Q

We use error handling in python to avoid inadvertent privilege escalation and data loss.
True or False

A

True

56
Q


:

What special character is used at the end of the first line in a control statement before the next line is indented?

$
+

A

:

57
Q


:

When opening a file, what special character gives read or write access depending on what is selected?

$
+

A

+

58
Q

What character opens a file in read binary mode?

r
b
a
w

A

b

59
Q

Which function combines all list objects into a single string?

split
join
pair
combine

A

split
join
pair
combine

60
Q

Which function converts a string into multiple list objects?

split
join
pair
combine

A

split

61
Q

The platform module can print the python complier for the OS
True or False

A

True

62
Q

If we import the random module and assign randon.randint(1.10) to a variable, what is the highest number it can have?

9
10
11
1

A

10

63
Q

What module did we use to run local shell commands?
sys
os
platform
socket

A

OS

64
Q

What is not true about functions?

Necessary to prevent code from becoming incomprehensible

Save the time and effort of writing the same code over and over again

Makes code maintenance more efficient and logical to follow

Begin with the ‘func’ keyword in python

A

Begin with the ‘func’ keyword in python

65
Q

In the function definition, arguments or parameters are passed between what two characters?

( )
[ ]
{ }
| |

A

( )

66
Q

What is the output of the following?
def func(num1, num2):
if num1 == 0:
return num2
else:
return func(num 1 -1, num2 + num2)
print (func(4 - 7))
11
14
17
3

A
67
Q

What is the default return data type for a function that does NOT use the return keyword?

int
boolean
None
string

A

None

68
Q

If a variable is defined within a function, what is the scope of a variable?

Local
Enclosing
Global
Built-In

A

Local

69
Q

Which is NOT present in the header of the function definition?

function name
parameter list
‘def’ starts and ‘:’ ends
return value

A

return value.encode())

70
Q

Recursion is calling an instance of a function on an instance of itself.
True or False

A

True

71
Q

What keyword do we use to define our own object in python and apply OOP?

def
class
methods
attributes

A

class