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
What is not a primitive data type in python? string integer boolean character
character
26
Complied languages are faster as first, but get slower with each thereafter True or False
False
27
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)
Strings are stored as ASCII characters by default
28
Which of these is not and IDE we mentioned? PyCharm IntelliJ IDEA Visual Studio Code C#
29
In python you can start a comment with both # and '""
True
30
True or False "Hello World!" is a complete string?
False
31
What data type is var in var = 7 string int float boolean
int
32
What data type is var in var = "cat"? string int float boolean
string
33
What data type is var in var = string int float boolean
float
34
What data type is var in var = False? string int float boolean
boolean
35
Loops are blocks of code that repeat logic as long as a condition is true
True
36
Loops repeat the indented code block on each iteration
True
37
How many numbers get printed? 3 7 9 None
9
38
What will be printed? 5 0-4 0-5 0
0-4
39
The print function always has to end with a new line character True or False
False
40
What gets printed? cat 3 catdog73 error
error
41
What gets printed? David John Cooper Nick, David,John,Cooper,Nick, 1,2,3,4 0,1,2,3,
0,1,2,3,
42
Which loop cannot be an infinite loop? for loop while loop nested loop all of these loops can be infinite
all of these loops can be infinite
43
The following prints and infinite loop True or False nums = [1, 2, 3] for i in range (len(nums)): print (i) nums.append(i)
False
44
The following prints and infinite loop start = 0 while start < 4: print(start)
True
45
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@
u@s@i@
46
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
ask for password until Pa$$w0rd is entered
47
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
while loop
48
What 2 python keywords do we use in combination to handle errors? try and except try and else try and error except and finally
try and except
49
Which method is the os module gets the path? os.getcwd os.walk os.stat os.listdir
os.getcwd
50
Which is not NOT a common exception type we mentioned? ZeroDivisionError TypeError KeyboardInterrupt CombinationError
CombinationError
51
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
cat mat
52
What python keyword forcefully raises an exception every time? except raise error else
53
The code inside a finally block only runs if the block is successful. True or False
False
54
What python keyword automatically close a file upon completion of its code block? open with open flush read
with open
55
We use error handling in python to avoid inadvertent privilege escalation and data loss. True or False
True
56
What special character is used at the end of the first line in a control statement before the next line is indented? # : $ +
:
57
When opening a file, what special character gives read or write access depending on what is selected? # : $ +
+
58
What character opens a file in read binary mode? r b a w
b
59
Which function combines all list objects into a single string? split join pair combine
split join pair combine
60
Which function converts a string into multiple list objects? split join pair combine
split
61
The platform module can print the python complier for the OS True or False
True
62
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
10
63
What module did we use to run local shell commands? sys os platform socket
OS
64
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
Begin with the 'func' keyword in python
65
In the function definition, arguments or parameters are passed between what two characters? ( ) [ ] { } | |
( )
66
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
67
What is the default return data type for a function that does NOT use the return keyword? int boolean None string
None
68
If a variable is defined within a function, what is the scope of a variable? Local Enclosing Global Built-In
Local
69
Which is NOT present in the header of the function definition? function name parameter list 'def' starts and ':' ends return value
return value.encode())
70
Recursion is calling an instance of a function on an instance of itself. True or False
True
71
What keyword do we use to define our own object in python and apply OOP? def class methods attributes
class