[go: up one dir, main page]

0% found this document useful (0 votes)
9 views4 pages

Untitled Document

The document contains a series of programming questions related to Python, covering topics such as string formatting, output of code snippets, properties of data structures, and dictionary operations. Each question provides multiple-choice answers, testing knowledge on Python syntax and behavior. The questions range from basic operations to more complex concepts in Python programming.

Uploaded by

magimaimagimai49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Untitled Document

The document contains a series of programming questions related to Python, covering topics such as string formatting, output of code snippets, properties of data structures, and dictionary operations. Each question provides multiple-choice answers, testing knowledge on Python syntax and behavior. The questions range from basic operations to more complex concepts in Python programming.

Uploaded by

magimaimagimai49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Compared to other ways of formatting strings, Python f-strings are:


(a)​ More readable
(b)​ Only supported on Python 2
(c)​ Less prone to errors
(d)​ Slower
2.What is the output of print(2 * 3 ** 3 * 4)
(a)​ 216
(b)​ 864
3. What is the output of the following code
x=6
y=2
print(x ** y)
print(x // y)
(a)​ 66 0
(b)​ 36 0
(c)​ 66 3
(d)​ 36 3
4.what is the output

var=(4)

print(type(4))
(a)​ <class 'list'>
(b)​ <class 'int'>
(c)​ <class 'tuple'>
(d)​ None of the above
5. Which of the following is not a property of a set?
(a)​ Ordered
(b)​ Mutable
(c)​ Does not allow duplicates
(d)​ All the above
6.What will be the output of the following code?
set1={1,2,3,4,5}
set1.clear()
set1
(a)​ Name Error
(b)​ Type Error
(c)​ set()
(d)​ None of the above
7. Which of the following functions cannot be applied to dictionaries?
(a)​ get()
(b)​ value()
(c)​ items()
(d)​ None of the above
8.What will be the output of the following code?
tup=(1,2,3,1,1.0,4)
print(tup.count(1))
(a)​ 2
(b)​ 3
(c)​ TypeError
(d)​ ValueError
9. Which of the following data structures are not ordered?
(a)​ Tuples
(b)​ Sets
(c)​ Dictionaries
(d)​ Both b and c
10.Which of the following does gives an error if
dic={1:’a’,2:’b’,3:’c’,’name’:’d’}?
(a)​ dic[1]
(b)​ dic.get(5)
(c)​ dic[4]
(d)​ All the above
11. Which of the following list comprehensions give the output as [1,3,5,7,9]?
(a)​ [i for i in range(10) if i%2==0]
(b)​ [i for i in range(9) if i%2==1]
(c)​ [i for i in range(9) if i%2==0]
(d)​ [i for i in range(10) if i%2==1]
12. Which of the following cannot be an element of a set?
(a)​ List
(b)​ Tuple
(c)​ Dictionary
(d)​ Both a and c
13. In the following code, what does this code print?:
sentence = "python rocks" print(sentence[2] + sentence[-3])
(a)​ tc
(b)​ "t c"
(c)​ "yc"
(d)​ "hc"
14. What would be the output of the following code?
s = 'doubled'
print(s[1:6][1:3])
A) oubleou
B) ub
C) ou
D) ubl
15. What would be the output of the following code?
s = 'completed'
print(s[2:5:3])
A) m
B) me
C) o
D) Blank Output
16. What would be the output of the following code?
s = 'coder'
print(s[::0])
A) redoc
B) coder
C) ValueError
D) IndexError
17. What would be the output of the following code?
s = 'follow'
print(s[3:8])
A) llow
B) low
C) lowlow
D) IndexError
18. Joining two strings with the + operator is called…

(a)​ String addition


(b)​ String joining
(c)​ String cheese
(d)​ String concatenation
19. What’s the value of x after this code snippet executes?
x = "1234" + 5
(a)​ '12345'
(b)​ 12345
(c)​ '1239'
(d)​ Trick question—this fails with a TypeError
20. Select the all correct way to remove the key marks from a dictionary
student = { "name": "Emma", "class": 9, "marks": 75 }
(a)​ student.pop("marks")
(b)​ del student["marks"]
(c)​ student.remove("marks")
(d)​ student.popitem("marks")
21. What is the output of the following dictionary operation
dict1 = {"name": "Mike", "salary": 8000}
temp = dict1.pop("age")
print(temp)
(a)​ KeyError: ‘age’
(b)​ None
22. What is the output of the following code
dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
(a)​ True
(b)​ False
23. What is the output of the expression print(-18 // 4)
(a)​ -4
(b)​ 4
(c)​ -5
(d)​ 5
24. What is the output of the following number conversion
z = complex(1.25)
(a)​ (1.25+0j)
(b)​ Value Error: Missing an imaginary part of a complex number
25. What is the output of the following code?
str = "pynative"
print (str[1:3])
(a)​ py
(b)​ yn
(c)​ pyn
(d)​ yna

You might also like