Download Python Review Questions Name

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Python Review Questions
Name:
1. What is the output of the following code?
x = 1
y = 2
x,y = y,y
print(x+y)
a. 4
b. 3
c. An exception is thrown.
d. 1
2. What is the output of the following code?
colors = ['Red', 'Black', 'White', 'Green']
if ‘green’ in colors:
print(‘Green Color’)
else:
print(‘No Green Color’)
a. An exception is thrown
b. No Green Color
c. Green Color
3. What is the output of the following code?
print(type((‘red’, ‘white’, ‘blue’, ‘green’)))
a. <class 'set'> b. <class 'tuple'>
c. <class 'dict'>
d. <class 'list'>
4. What is the output of the following code?
colors = ['Red', 'Black', 'White', 'Green']
x = colors.index(“White”)
print(x)
a. 3
b. 4
c. 1
d. 2
5. What is the output of the following code?
x = 12
y = 18
x = y
y = x
print(x,y)
a. 18 18
b. 12 18
6. What is the output of the following code?
x = ‘abcd’
y = 10
print(x+y)
c. 18 12
d. 12 12
a. abcd10
b. An exception is thrown.
c. abcd 10
7. What will be the output of the following command?
print(type([1,2,3]))
a. <class 'tuple'>
b. <class 'list'>
c.<class 'set'>
8. What is the output of the following code?
a =
b =
c =
sum
for
1
2
’3′
= 0
x in (a,b,c):
if isinstance(x, int):
sum += x
print(sum)
a. 3
b. 4
c. 1
d. 2
9. What is the output of the following code?
colors = ['Red', 'Black', 'White', 'Green']
print(colors[-2][-2])
a. n
b. en
c. t
d. c
10. What is the output of the following code?
x = 0
for y in range(0,5):
x+= y
print(x)
a. 5
b. 10
c. 15
11. What is the output of the following code?
x = sum(range(3))
print(x)
a. 3
b. An exception is thrown
12. What is the output of the following code?
x = {1:’a', 2:’b', 3:’c'}
x = {}
print(len(x))
c. 6
d. 2
d. 10
a. 3
b. An exception is thrown
c. 0
13. What will be the output of the following command?
print(type(1/3))
a. <class 'complex'> b. <class 'int'> c. <class 'float'>
14. What is the output of the following code?
print(type({“color1″:’red’, “color2″:’white’, ‘color3′:’blue’}))
a. <class 'dict'>
b. <class 'tuple'>
c. <class 'list'> d. Array
15. What is the output of the following code?
x = {1:’a', 2:’b', 3:’c'}
del x[1]
x[1] = ‘d’
del x[2]
print(len(x))
a. 3
b. 4
c. 2
d. 1
16. What will be the value of colors[-2]?
colors = ['red', 'white', 'blue', 'green']
a. 'blue'
b. 'white'
c. 'red'
d. 'green'
17. What is the output of the following code?
import math
print(math.floor(5.6))
a. 5.0
b. 6
c. 5.5
d. 5
18. What is the output of the following code?
x=0
for i in range(2, 10, 2):
x = x + i
print(x)
a. 2 4 6 8 10
b. 2 6 12 20
19. What is the output of the following code?
x = 12
y = 18
x = y
c. 10 11
print(x,y)
a. 18 12
b. 18 18
c. 12 12
d. 12 18
20. What is the output of the following code?
x = 1
print(++++x)
a. 2
b. 4
c. 1
d. 3
21. Which of the following statements is Python comment?
a. None of the above.
b. * This is a Python comment.
c. // This is a Python comment.
d. # This is a Python comment.
22. What is the output of the following code?
def MyFunction():
“We are here at w3resource Python beginner skill test”
return 1
print(MyFunction.__doc__[12:14])
a. re
b. None of the above.
c. at
d. w3resource
23. What is the output of the following code?
def MyFunc(a,b,c,d):
print(a+b)
x = [1, 2, 3, 4]
MyFunc(*x)
a. 2
b. 1
c. 3
d. 4
24. Which of the following code will add a new color ‘black’ at the end of the list?
colors = ['red', 'white', 'blue', 'green']
a. colors.append('black')
b. colors.add('black')
c. colors+=('black')
d. colors.insert('black')
Portions taken from http://w3resource.com/w3skills/python-beginner-quiz/
Related documents