Python Exam Questions and Answers
Which of the following is correct about Python?
a. Python is a high-level, interpreted, interactive and object-oriented scripting language.
b. Python is designed to be highly readable.
c. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.
d. All of the above
d. All of the above.
Is Python case sensitive when dealing with identifiers?
a. yes
b. no
c. it depends on context
d. it depends on data type
a. yes
Which of the following is an invalid variable?
a. my_string
b. __a
c. 1st_string
d. foo_24
c. 1st_string
All keywords in Python are in
a. lower case
b. UPPER CASE
c. Capitalized
d. None of the above
d. None of the above
______________(str) is the function to run in the shell to find out details about how to use str() and the type of data it accepts and returns.
help
Which of the following is an invalid statement?
a. abc = 1,000,000
b. a b c =
c. a,b,c = 1, 2, 3
d. a_b_c = 4,000,000
b. a b c =
Which one of the following have the highest precedence in the expression?
a. Exponential
b. Addition
c. Multiplication
d. Parentheses
d. Parentheses
Following set of commands are executed in shell, what will be the output?
str = "hello"
str[:2]
he; because you are printing only the first two bytes of string.
The following is displayed after a print() call:
tom
dick
harry
Select the function call that results in this output
a. print("ttom
tdick
tharry")
b. print("ttom tdick tharry")
c. print(" tom dick harry")
d. print("ttomntdickntharry")
d. print("ttomntdickntharry")
What is the output of the following code:
x = ['ab', 'cd']
for i in x:
- i. upper()
print(x)
['ab', 'cd']
What is the output of the following?
True = False
while True:
- print(True)
- break
a. True
b. False
c. None
d. none of the above
d. none of the above
What is the output of the following?
x = 'abcdef'
i = "a"
while i in x:
- print ('i', end = " ")
and why?
i i i i i i i i .....
because, you are running a while loop, therefore until i is not found in x it will continue to run. "a" will always be found in the string of characters 'abcdef', therefore: i i i i i i i, will never end.
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
- print(())
a. a b c d
b. 0 1 2 3
c. error
d. 1 2 3 4
a. a b c d
What is the output of the following?
x = 2
for i in range(x):
- x += 1
- print(x)
a. 0 1 2 3 4 ....
b. 0 1
c. 3 4
d. 0 1 2 3
c. 3 4
What is the output of the following?
string = "my name is x"
for i in string:
- print(i, end = ", ")
a. m, y, , n, a, m, e, , i, s, , x,
b. m, y, , n, a, m, e, , i, s, , x
c. my, name, is, x,
d. error
a. m, y, , n, a, m, e, , i, s, , x,
What is the output when the following code is executed?
print(r"nhello")
a. a new line and hello
b. the letter r and then hello
c. error
d. nhello
c. error
The output of the following?
print("Hello {name1} and {name2}".format(name1 = 'foo', name2 = 'bin'))
gives you: Hello foo and bin
Why?
Because the arguments are accessed by their names.
What is the output of the following?
print('abcdef12'.replace('cd', '12'))
a. abcdef12
b. ab12ef12
c. ab12efcd
d. none of the above
b. ab12ef12
Which of the following operator in python evaluates to true if it does not finds a variable in the specified sequence and false otherwise?
a. **
b. //
c. is
d. not in
d. not in
You have the following code:
d = {"john":40, "peter":45}
print(d["john"])
What type of data structure is 'd'? Also, what do you receive from the second line? (separate your answers by a single space)
d is a dictionary
you receive the number 40 because "john":40
Which of the following statement terminates the loop statement and transfers execution to the statement immediately following the loop?
a. continue
b. break
c. exit
d. pass
b. break
Which of the following functions reverses objects of lists in place?
a. ([func])
b. se()
c. (obj=list[-1])
d. e(obj)
b. se()
Content preview
Python Exam Questions and Answers
Which of the following is correct about Python?
a. Python is a high-level, interpreted, interactive and object-oriented scripting language.
b. Python is designed to be highly readable.
c. It uses English keywords frequently where as other languages use punctuation, and it
has fewer syntactical constructions than other languages.
d. All of the above - answer d. All of the above.
Is Python case sensitive when dealing with identifiers?
a. yes
b. no
c. it depends on context
d. it depends on data type - answer a. yes
Which of the following is an invalid variable?
a. my_string
b. __a
c. 1st_string
d. foo_24 - answer c. 1st_string
All keywords in Python are in
a. lower case
b. UPPER CASE
c. Capitalized
d. None of the above - answer d. None of the above
______________(str) is the function to run in the shell to find out details about how to
use str() and the type of data it accepts and returns. - answer help
Which of the following is an invalid statement?
a. abc = 1,000,000
b. a b c = 1000 2000 3000
c. a,b,c = 1, 2, 3
d. a_b_c = 4,000,000 - answer b. a b c = 1000 2000 3000
Which one of the following have the highest precedence in the expression?
, a. Exponential
b. Addition
c. Multiplication
d. Parentheses - answer d. Parentheses
Following set of commands are executed in shell, what will be the output?
>>> str = "hello"
>>> str[:2]
>>> - answer he; because you are printing only the first two bytes of string.
The following is displayed after a print() call:
tom
dick
harry
Select the function call that results in this output
a. print("\ttom
\tdick
\tharry")
b. print("\ttom \tdick \tharry")
c. print(" tom dick harry")
d. print("\ttom\n\tdick\n\tharry") - answer d. print("\ttom\n\tdick\n\tharry")
What is the output of the following code:
x = ['ab', 'cd']
for i in x:
-> i. upper()
print(x) - answer ['ab', 'cd']
What is the output of the following?
True = False
while True:
-> print(True)
-> break
a. True
b. False
c. None
d. none of the above - answer d. none of the above
What is the output of the following?
x = 'abcdef'
i = "a"
while i in x:
-> print ('i', end = " ")
and why? - answer i i i i i i i i .....