0% found this document useful (0 votes)
22 views11 pages

Python MCQ Revision Practice Sheet

This document contains a guided practice sheet with 48 multiple choice questions about Python concepts like variables, data types, operators, and functions. It is intended as a revision tour for key Python topics for a computer science course. The questions cover core Python topics from variables and data types to operators, strings, lists, dictionaries, loops, and functions. It includes the name and credentials of the lecturer who created the practice sheet.

Uploaded by

GKJ kalaiyagam
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)
22 views11 pages

Python MCQ Revision Practice Sheet

This document contains a guided practice sheet with 48 multiple choice questions about Python concepts like variables, data types, operators, and functions. It is intended as a revision tour for key Python topics for a computer science course. The questions cover core Python topics from variables and data types to operators, strings, lists, dictionaries, loops, and functions. It includes the name and credentials of the lecturer who created the practice sheet.

Uploaded by

GKJ kalaiyagam
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

GUIDED PRACTICE SHEET PYTHON REVISION TOUR

Computer Science New 083


Python Revision Tour –I & II
IMPORTANT MCQ’s
2021-22

Type –A- MCQ


1. Which of the following is an invalid variable?

(a) my_day_2
(b) 2nd_day
(c)Day_two
(d) _2

2. Which of the following is not a keyword?

(a) eval
(b) assert
(c) nonlocal
(d) pass

3. Which of the following cannot be a variable?

(a) init
(b) in
(c) it
(d) on

4. Which of these is not a core data type?

(a) Lists
(b) Dictionary
(c) Tuples
(d) Class

5. How would you write xy in Python as an expression?

(a) x^y
(b) x**y
(c) x^^y
(d) none of these

6. What will be the value of the expression?

14 +13 % 15

(a) 14
(b) 27
(c) 12

POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE


GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(d) 0
7. Evaluate the expression given below if A = 16 and B = 15.

A%B//A

(a) 0.0
(b) 0
(c) 1.0
(d) 1

8. What is the value of x?

x = int(13.25 4/2)

(a) 17
(b) 14
(c) 15
(d) 23

9. The expression 8/4/2 will evaluate equivalent to which of the following


expressions:

(a) 8/(4/2)
(b) (8/4)/2

10. Which among the following list of operators has the highest precedence?

+ , -, **, %, /, << , >>, |

(a) <<, >>


(b) **
(c) |
(d) %

11. Which of the following expressions results in an error?

(a) float('12')
(b) int('12')
(c) float('12.5')
(d) int('12.5')

12. Which of the following statement prints the shown output below?
hello\example\[Link]

(a) print("hello\example\[Link]")
POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE
GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(b) print("hello\\example\\[Link]")
(c) print("hello\"example \"[Link]")
(d) print("hello"\example"\[Link]")
13. Which value type does input() return?
(a) Boolean
(b) String
(c) Int
(d) Float

14. Which two operators can be used on numeric values in Python?

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

15. Which of the following four code fragments will yield following output?
Eina
Mina
Dika

Select all of the function calls that result in this output


(a)
print('''Eina
\nMina
\nDika''')
(b) print('''EinaMinaDika''')
(c) print('Eina\nMina\nDika')
(d)
print('Eina
Mina
Dika')

16. Which of the following is valid arithmetic operator in Python:

(a) //
(b) ?
(c) <
(d) and

17. The numbered position of a letter in a string is called .

(a) position
(b) integer position
(c) index
(d) location

18. The operator tells if an element is present in a sequence or not.


(a) exists
POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE
GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(b) in
(c) into
(d) inside
19. The keys of a dictionary must be of types.
(a) Integer
(b) mutable
(c) immutable
(d) any of these

20. Following set of commands is executed in shell, what will be the output?

>>>str = "hello"
>>>str[ : 2]
>>>

(a) he
(b) lo
(c) olleh
(d) hello

21. What data type is the object below?

L = [1, 23, 'hello', 1]

(a) list
(b) dictionary
(c) array
(d) tuple

22. What data type is the object below?

L = 1, 23, 'hello', 1

(a) list
(b) dictionary
(c) array
(d) tuple

23. To store values in terms of key and value, what core data type does
Python provide?

(a) list
(b) tuple
(c) class
(d) dictionary

24. What is the value of the following expression?

3 + 3.00, 3**3.0
POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE
GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(a) (6.0, 27.0)


(b) (6.0, 9.00)
(c) (6, 27)
(d) [6.0, 27.0]
(e) [6, 27]
25. List AL is defined as follows:

AL = [1, 2, 3, 4, 5]

Which of the following statements removes the middle element 3 from it so


that the list AL equal [1, 2, 4, 5]?

(a) del a[2]


(b) a[2 : 3] = []
(c) a[2:2] = []
(d) a[2] = []
(e) [Link](3)

26. Which two lines of code are valid strings in Python?

(a) This is a string


(b) 'This is a string'
(c) (This is a string)
(d) "This is a string"

27. You have the following code segment:

String1 = "my"
String2 = "work"
print(String1 + string2)

What is the output of this code?

(a) my work
(b) work
(c) mywork
(d) my

28. You have the following code segment

String1 = "my"
String2 = "work"
print(String1 + [Link]())

What is the output of this code?

(a) mywork
(b) MY Work
POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE
GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(c) myWORK
(d) My Work

29. Which line of code produces an error?


(a) "one" + 'two'
(b) 1+ 2
(c) "one"+ "2"
(d) '1' + 2
30. What is the output of this code?

>>> int("3" + " 4")

(a) "7"
(b) "34"
(c) 34
(d) 24

31. Which line of code will cause an error?

1. num = [5, 4, 3, [2], 1]


2. print(num [0])
3. print(num[3][0])
4. print (num[5])

(a) Line 3
(b) Line 2
(c) Line 4
(d) Line 1

32. Which is the correct form of declaration of dictionary?

(a) Day = {1 : 'Monday', 2 : 'Tuesday', 3 : 'wednesday'}


(b) Day = {1 ; 'Monday', 2 ; 'Tuesday', 3 ; 'wednesday'}
(c) Day = [1 : 'Monday', 2 : 'Tuesday', 3 : 'wednesday']
(d) Day = {1 'Monday', 2 'Tuesday', 3 'wednesday'}

33. Identify the valid declaration of L:

L = [1, 23, 'hi', 6]

(a) list
(b) dictionary
(c) array
(d) tuple

34. Which of the following is not considered a valid identifier in Python?

POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE


GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(a) two2
(b) _main
(c) hello_rsp1
(d) 2 hundred

35. What will be the output of the following code-print("100+200")?

(a) 300
(b) 100200
(c) 100+200
(d) 200
36. Which amongst the following is a mutable data type in Python?
(a) int
(b) string
(c) tuple
(d) list

37. pow() function belongs to which library?


(a) math
(b) string
(c) random
(d) maths

38. Which of the following statements converts a tuple into a list?


(a) len(string)
(b) list(string)
(c) tup(list)
(d) dict(string)

39. The statement: bval = str i > str2 shall return. .... As the output if two
strings str1 and str2 contains "Delhi" and "New Delhi".
(a) True
(b) Delhi
(c) New Delhi
(d) False

40. What will be the output generated by the following snippet?


a = [5, 10, 15, 20, 25]
k=1
i = a[1] + 1
j = a[2] +1
m = a[k+1]
print (i, j, m)

(a) 11 15 16
(b) 11 16 15
(c) 11 15 15

POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE


GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(d) 16 11 15

41. The process of arranging the array elements in a specified order is termed
as:
(a) Indexing
(b) Slicing
(c) Sorting
(d) Traversing

42. Which of the following Python functions is used to iterate over a sequence
of number by specifying a numeric end value within its parameters?

(a) range()
(b) len()
(c) substring()
(d) random()
43. What is the output of the following?

d = {0: 'a', 1: 'b', 2: 'c'}


for i in d:
print(i)

(a)
0
1
2

(b)
a
b
c

(c)
0
a
1
b
2
c

(d)
2
a
2
b
2
c

44. What is the output of the following?


POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE
GUIDED PRACTICE SHEET PYTHON REVISION TOUR

x = 123
for i in x:
print(i)

(a) 1 2 3
(b) 123
(c) error
(d) infinite loop

45. Which arithmetic operators cannot be used with strings?

(a) +
(b) *
(c) -
(d) all of the above
46. What will be the output when the following code is executed?
>>> str1="helloworld"
>>> stri[:-1]

(a) dlrowolleh
(b) hello
(c) world
(d) helloworld

47. What is the output of the following statement?

print ("xyyzxyzxzxyy".count ('yy', 1))

(a) 2
(b) 0
(c) 1
(d) Error

48. Suppose list1 [0.5 * x for x in range(0, 4)], list1 is:

(a) [0, 1, 2, 3]
(b) [0, 1, 2, 3, 4]
(c) [0.0, 0.5, 1.0, 1.5]
(d) [0.0, 0.5, 1.0, 1.5, 20]

49. Which is the correct form of declaration of dictionary?

(a) Day={1:'monday',2:'tuesday',3:'wednesday'}

POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE


GUIDED PRACTICE SHEET PYTHON REVISION TOUR

(b) Day=(1;'monday',2;'tuesday',3;'wednesday')
(c) Day=[1:'monday',2:'tuesday',3:'wednesday']
(d) Day={1 monday',2 tuesday',3 wednesday']

50. Identify the valid declaration of L: L = [1, 23, 'hi', 6]

(a) list
(b) dictionary
(c) array
(d) tuple

Type –B-Fill-Ups
1. The smallest individual unit in a program is known as a .
2. A token is also called a .
3. A is a word having special meaning and role as specified by programming
language.
4. The data types whose values cannot be changed in place are called types.
5. In a Python expression, when conversion of a value's data type is done

automatically by the compiler without programmer's intervention, it is called .

6. Strings in Python store their individual letters in Memory in location.

7. Operator when used with two strings, gives a concatenated string.

8. Operator when used with a string and an integer gives an error.

9. Part of a string containing some contiguous characters from the string is called

10. The operator when used with a list/string and an integer, replicates the

list/string

Type –C-True or False


1. The expression int(x) implies that the variable x is converted to integer.

2. The value of the expressions 4/ (3*(2 - 1)) and 4/3*(2- 1) is the same.

3. The value of the expressions 4/ (3*(4 - 2) and 4/3*(4-2) is the same.

4. The expression 2**2**3 is evaluated as: (2**2) **3.

5. A string can be surrounded by three sets of single quotation marks or by three

POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE


GUIDED PRACTICE SHEET PYTHON REVISION TOUR

sets of double quotation marks.

6. Do both the following represent the same list?

['a', b, c']

['c', 'a', 'b']

7. A list may contain any type of objects except another list.

8. There is no conceptual limit to the size of a list.

9. All elements in a list must be of the same type.

10. A given object may appear in a list more than once.

POOVIZHI.M MCA., [Link]., LECTURER IN COMPUTER SCIENCE

Common questions

Powered by AI

Key-value pairs in Python are stored in dictionaries. A dictionary is defined using curly braces {} with pairs separated by commas, e.g., Day = {1: 'Monday', 2: 'Tuesday'}. Retrieval is done using keys, allowing quick access to values, like 'Day[1]' which gives 'Monday'. This method is efficient for data lookup and is more intuitive when the relationship between values and keys is meaningful, as it provides constant time complexity for access, insertions, and deletions .

Python treats identifiers based on its lexical rules where an identifier must start with a letter (A-Z or a-z) or an underscore (_), followed by letters, numbers, or underscores. For example, '2hundred' is invalid as it starts with a digit, while '_main' or 'hello_rsp1' are valid identifiers. This impacts how developers assign meaningful variable names while adhering to these rules to maintain code readability and prevent syntax errors .

List slicing in Python allows you to extract parts of a list by specifying a range of indices. The syntax for slicing is list[start:stop:step]. For example, with the list [5, 10, 15, 20, 25], the slice list[1:4] returns [10, 15, 20], which includes elements from index 1 to 3. Slicing provides flexibility in accessing subsets of list elements and supports advanced operations like reversing a list with list[::-1].

In Python, mutable types are those whose values can be changed after they are created, such as lists and dictionaries. Immutable types, like tuples and strings, cannot be changed once they are created. This distinction is crucial because it affects how objects are handled in memory. Immutable objects can be shared between different parts of a program without worrying that their values will change, whereas mutable objects require careful handling to prevent unintended modifications. This distinction impacts how you design your program and manage memory .

Storing data using mutable data types like lists in Python allows for dynamic data manipulation, such as appending, removing, or altering elements. This flexibility supports algorithms that require frequent data updates. However, it also necessitates careful handling to prevent unintended modifications, which can lead to bugs due to shared references. Proper program design involves using immutable data when possible to enhance predictability and safety, especially when data sharing between different functions or modules is involved .

The result of executing the code segment 'print("100+200")' will be the string '100+200'. The '+' symbol here is not treated as an arithmetic operator because it is within a string literal, which means the expression is not evaluated mathematically. This highlights the concept of string literals where all contained characters, including symbols that are typically operators, are treated as plain text .

Operator precedence in Python determines the order in which operations are performed in expressions. For example, the expression '3 + 5 * 2' will be evaluated as '3 + (5 * 2)' because the multiplication '*' operator has a higher precedence than the addition '+' operator. Understanding operator precedence is important to correctly predict and control the flow of complex expressions. Without proper understanding, expressions might not produce the desired results .

The expression '3 + 3.00' results in '6.0' because the integer '3' is implicitly converted to a float to match the type of '3.00'. The '3**3.0' expression results in '27.0', with the integer '3' being coerced into a float '3.0' for exponentiation. Type coercion ensures that operations between mixed types are feasible by converting them to a common type. This is essential for maintaining consistency and avoiding type errors during calculations involving mixed data types .

Tuple unpacking in Python allows multiple variables to be assigned values from a tuple simultaneously, enhancing code efficiency and readability by reducing boilerplate code. For instance, with 'x, y = (3, 4)', both 'x' and 'y' are assigned in a single line. This technique is particularly useful when returning multiple values from a function or when iterating with 'enumerate()' in loops, improving clarity and alignment with Pythonic practices .

The 'range()' function in Python generates a sequence of numbers and is commonly used in for-loops to iterate over a sequence. For example, 'for i in range(5)' generates numbers from 0 to 4, iterating five times. 'range()' can take up to three arguments: start, stop, and step, allowing for customized ranges. Using 'range()' is efficient for loops because it does not create a list in memory, but a range object that generates elements on demand .

You might also like