TST

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1. Which operator is used on numeric values on python?

a) @ b) % c) ) d) #

2. Which operator is used to check whether two variables are same or not?

a) – b) == c) ! d) =

3. You have the following code segment –


string1=”my”
string2=work”
print (string1+string2.upper ())
What is the output of this code?

a) mywork c) myWORK
b) MY Work d) My Work.

4. Given the numeric variable Num1, which lines of code properly prints the value?

a) Print(“%d”) c) Print(Num1)
b) Print(“%d”,Num1) d) Print(“%d Num1”)

5. Suppose s is assigned as follows: s=’foobar’.All of the following expressions produce the same result except
one. Which one?

a) s[::-5] c) s[::-1][-1] e) s[::5]


b) s[::-1][::-5] d) s[0]+s[-1]

6. Which value type does input() return?

a) boolean c) int
b) string d) float

7. What will be the output of the following code?


tuple_a=’a’,’b’
tuple_b=(‘a’,’b’)
print(tuple_a==tuple_b)

a) 0 b) 1 c) False d) True

8. What will be the output produced by following code?


>>grade1=80
>>grade2=90
>>average1= (grade1+grade2)/2
>>average2=grade1+grade2/2
>>average1, average2

a) 85.0,125.0 c) 85.0,85.0
b) (85.0,125.0) d) (125.0,85.0)

9. What will the following expressions evaluate to –


>>8/4/2, 8/ (4/2), (8/4)/2
a) 1,4,1 b) 1.0,4.0,1.0 c) 1.0,1.0,1.0 d) 4.0,4.0,4.0

10. Which is not a tokens from the following :

a) keywords c) operators
b) Expressions. d) Literals.

11. Choose valid arithmetic operator-

e) // f) ? g) < h) and

12. What is the output of the following code?


>>>a=2**(3**2)
>>>b=(2**3)**2
>>>c=2**3**2
>>> a,b,c
a) 533,64,533 b) 512,64,512 c) 64,512,64 d) 512,64,64
13. What data type is the object below?
L= [1, 23,’hello’, 1]
a) List b) Dictionary c) Array d) tuple
14. What data type is the object below?
L= 1, 23,’hello’, 1
a) List b) Dictionary c) Array d) tuple
15. To store values in terms of key and value, what core data type does python provide?
a) List b) Dictionary c) Array d) tuple
16. Is python case sensitive when dealing with identifiers?
a) Yes c) Machine dependent
b) No d) None of the mentioned
17. Which of the statements will print the following-
hello-how-are-you
a) print(‘hello’,’how,’are’,’you’)
b) print(‘hello’,’how,’are’,’you’+’-‘*4)
c) print(‘hello-’,’how-are-you’)
d) print('hello','how','are','you',sep='-')
18. predict the output:
count=0
while count<10:
print(“hello”)
count+=1
a) print “hello” 9 times. c) print “hello” 11 times.
b) print “hello” 10 times. d) none of these.
19. Which of the following commands will create a list?

a) list1 = list() c) list1 = list([1, 2, 3])


b) list1 = [] d) all of the mentioned
20. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], which of the following is correct syntax for slicing operation?

a) print(list1[0]) c) print(list1[:-2])
b) print(list1[:2]) d) all of the mentioned
21. Suppose
a) Error list1 is [2, 33, 222, 14,c)
25],
25What is list1 [-1]?
b) None d) 2
22. What will be the output of the following Python code?
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
a) 1 c) 5
b) 2 d) Error
23. What will be the output of the following Python code?
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
a) True c) Error
b) False d) None
24. What will be the output of the following Python code?
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
a) [2, 3, 9] c) [1, 4, 8]
b) [1, 2, 4, 3, 8, 9] d) (1, 4, 8)
25. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
a) True c) None
b) False d) Error
26. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
a) True c) None
b) False d) Error
27. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

a) d.delete(“john”:40) c) del d[“john”]


b) d.delete(“john”) d) del d(“john”:40)
28. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
print(list(d.keys()))
a) [“john”, “peter”] c) (“john”, “peter”)
b) [“john”:40, “peter”:45] d) (“john”:40, “peter”:45)
29. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we
use?

a) d.size() c) size(d)
b) len(d) d) d.len()
30. What is the order of precedence in python?

i) Parentheses iii) Multiplication v) Addition


ii) Exponential iv) Division vi) Subtraction
options are -:
a) i,ii,iii,iv,v,vi c) ii,i,iv,iii,v,vi
b) ii,i,iii,iv,v,vi d) i,ii,iii,iv,vi,v

You might also like