stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Python Quiz Flashcards | StudBud
Explore
/
Python Quiz
Python Quiz
30 terms
·
StudBud Administration
·
15 plays
Basic understanding of Python Language.
Flashcards
30 cards
F
Practice quiz
P
Host live
L
Questions
30
Answers
1
Which of the following is a valid way to start a function in Python?
function someFunction():
def someFunction()
function someFunction()
def someFunction():
2
Which of the following statements is NOT true about Python?
Python can run on any type of platform
Python’s syntax is much like PHP
Python can be used to generate dynamic web pages
Python can be used for web development
3
Which of the following is a valid dictionary in Python?
myExample = (‘someItem’=>2, ‘otherItem’=>20)
myExample = {‘someItem’=>2, ‘otherItem’=>20}
myExample = {‘someItem’: 2, ‘otherItem’: 20}
myExample = (‘someItem’: 2, ‘otherItem’: 20)
4
What can you put before and after a section to make all of the lines a comment?
(comment)
///
”’
###
5
Which of the following is a valid for loop in Python?
for a loop 3:
for(a = 0; a < 3; a++)
for a in range(1,3):
for a in range(3)
6
What is the proper way to open a file that you intend to read from?
f = open(“read”,”test.txt”)
f = open(“test.txt”, “r”)
f = open(“r”,”test.txt”)
f = open(“test.txt”, “read”)
7
How would you print the second item in the list variable “example”?
print(example(2))
print(example[2])
echo(example[2])
print(example[1])
8
Which of the following is a valid list in Python?
sampleList = (1,2,3,4,5)
sampleList = [1,2,3,4,5]
sampleList = {1,2,3,4,5}
sampleList = /1,2,3,4,5/
9
How do you check to see what is the type of variable "example"?
getType(example)
Type(example)
type(example)
example.type
10
What is the superclass of a class?
The class it is an instance of
The instance it inherits from
The first class that inherits from it
The class it inherits from
11
What keyword would you use to add an alternative condition to an if statement?
else if
None of the above
elif
elseif
12
Which one of the following is a valid Python if statement
if a >= 22
if (a >= 22)
if a >= 22:
if (a => 22)
13
What would happen to the file as soon as “f = open(“test.txt”,”w”)” is executed?
Append code to the content and save the file
The file’s contents will be erased
Nothing
Nothing, unless the code following it writes to the file
14
In Python, what is one function to output content to the console?
output
print
echo
console.log
15
What is anonymous function called?
lamda
lamdas
lambda
lombda
16
What is the difference between a class and an object in Python?
There is no difference between a class and an object
Objects are not able to be called.
Classes are made from iterations while objects are not.
Objects are created from classes.
17
What is the proper way to open a file that you plan to write to?
f = open(“test.txt”,”w”)
f = open(“w”,”test.txt”)
f = open(“test.txt”,”write”)
f = open(“write”,”test.txt”)
18
Which of the following is a valid way to start a while loop in Python?
while loop a < 10
while(a < 10)
while a < 10:
while loop a < 10:
19
What symbol can you use to comment out one line of code?
(comment)
#
//
*
20
What would the statement “print(‘%.2f’ % 123.444)” print out?
44
123.44
123.444
12
21
Which of the following is a valid tuple in Python?
sampleTuple = {1,2,3,4,5}
sampleTuple = /1,2,3,4,5/
sampleTuple = (1,2,3,4,5)
sampleTuple = [1,2,3,4,5]
22
What would [abc][def] match?
Either "abc" or "def"
Only "abc" and "def"
Any three letters out of "abc", then any three from "def"
Any letter out of "abc", then any out of "def"
23
How do you create a variable “a” that is equal to 2?
variable a = 2
a = 2
int a = 2
var a = 2
24
How would you cast the int variable “a” that is equal to 2 into the string “2”?
int(a)
string(a)
castToString(a)
str(a)
25
Which piece of code shows a new class Spam inheriting from Egg?
class Egg(Spam):
class Spam(Egg):
class (Spam)Egg:
class Spam.Egg:
26
What would [1-5][0-9] match?
Any two-digit number from 10 to 59
Any four digit number
10, 19, 50, or 90
Any two-digit number
27
What is the keyword used after the try statement to handle exceptions?
exception
catch
catch(a)
except
28
How would you cast the string variable “a” that is equal to “2” into the integer 2?
castToInteger(a)
castToInt(a)
integer(a)
int(a)
29
Which of the following tasks CANNOT be performed using regular expressions?
Checking whether an email address is real
Checking syntax of the email address
Checking whether an email address is of the correct format
Changing the URL part of an email address
30
Which of the following is not a valid assignment operator?
-=
*=
X=
+=