Python Exam Review Flashcards
If an object’s reference count is 0, memory for that object is deallocated and marked for garbage collection. True of False
True
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
Declare the variable type before assigning a value or object
The input function returns an object of what data type?
string
What is the preferred method for string formatting in python 3.6+?
f string
Converting a variable to a different type is NOT called type casting. True or False
False
What is the comparison operator to see if two objects are explicitly equal?
==
In python, (2**3) evaluates to?
6
8
6.0
8.0
8
In python, (18 % 7) evaluates to?
2.57
4.0
2
4
4
In python, (18//7) evaluates to?
4
4.0
2
2.0
2
If we give XOR True and True, it will return?
False
Taking a subsection of a string or list is called “slicing” True of False
True
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
The final else is typed with explicit condition
What is the only mathematical operator we can use on two strings?
+ plus sign
What is the only mathematical operator we can do on a string and an int?
+
-
*
/
- multipication
Which advance data structures have we not discussed?
Dictionary
Tuple
List
Queue
Queue
The inputs to a string or list slice are start, stop, step respectively True or False
True
What data type do we index on an int?
Dictionary
tuple
list
queue
List
What type of data do we index on a string?
dictionary
tuple
list
queue
dictionary
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
False
What variable type is var, if we assign var = “Hello World”
string
dictionary
list
tuple
Tuple
What is regarded as the lowest level source code?
Python
C#
Java
Machine Code
Machine Code
What is the default implementation type of python that we get from python.org
Cypthon
Jython
IronPyton
Phyton2
Cypthon
Python is best at low level programming?
True or False
False
In Pycharm, what do you usually configure for every new project?
Theme
Font
Interpreter
Enable zoom with mouse wheel
Interpreter
What is not a primitive data type in python?
string
integer
boolean
character
character
Complied languages are faster as first, but get slower with each thereafter
True or False
False
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
Which of these is not and IDE we mentioned?
PyCharm
IntelliJ IDEA
Visual Studio Code
C#
In python you can start a comment with both # and ‘””
True
True or False “Hello World!” is a complete string?
False
What data type is var in var = 7
string
int
float
boolean
int
What data type is var in var = “cat”?
string
int
float
boolean
string
What data type is var in var =
string
int
float
boolean
float
What data type is var in var = False?
string
int
float
boolean
boolean
Loops are blocks of code that repeat logic as long as a condition is true
True
Loops repeat the indented code block on each iteration
True
How many numbers get printed?
3
7
9
None
9
What will be printed?
5
0-4
0-5
0
0-4
The print function always has to end with a new line character
True or False
False
What gets printed?
cat
3
catdog73
error
error
What gets printed?
David John Cooper Nick,
David,John,Cooper,Nick,
1,2,3,4
0,1,2,3,
0,1,2,3,
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
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
The following prints and infinite loop
start = 0
while start < 4:
print(start)
True
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@
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
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
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
Which method is the os module gets the path?
os.getcwd
os.walk
os.stat
os.listdir
os.getcwd
Which is not NOT a common exception type we mentioned?
ZeroDivisionError
TypeError
KeyboardInterrupt
CombinationError
CombinationError
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
What python keyword forcefully raises an exception every time?
except
raise
error
else
The code inside a finally block only runs if the block is successful.
True or False
False
What python keyword automatically close a file upon completion of its code block?
open
with open
flush
read
with open
We use error handling in python to avoid inadvertent privilege escalation and data loss.
True or False
True
:
What special character is used at the end of the first line in a control statement before the next line is indented?
$
+
:
:
When opening a file, what special character gives read or write access depending on what is selected?
$
+
+
What character opens a file in read binary mode?
r
b
a
w
b
Which function combines all list objects into a single string?
split
join
pair
combine
split
join
pair
combine
Which function converts a string into multiple list objects?
split
join
pair
combine
split
The platform module can print the python complier for the OS
True or False
True
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
What module did we use to run local shell commands?
sys
os
platform
socket
OS
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
In the function definition, arguments or parameters are passed between what two characters?
( )
[ ]
{ }
| |
( )
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
What is the default return data type for a function that does NOT use the return keyword?
int
boolean
None
string
None
If a variable is defined within a function, what is the scope of a variable?
Local
Enclosing
Global
Built-In
Local
Which is NOT present in the header of the function definition?
function name
parameter list
‘def’ starts and ‘:’ ends
return value
return value.encode())
Recursion is calling an instance of a function on an instance of itself.
True or False
True
What keyword do we use to define our own object in python and apply OOP?
def
class
methods
attributes
class