CBSE Python

CS-IT-IP-AI and Data Science Notes, QNA for Class 9 to 12

150+ MCQ Revision Tour of python class 12

Unit -1: computational thinking and programming-2, topic: revision of python topics covered in class xi.

1. Which of the following is a valid identifier:

c) Same-type

Show Answer

2. Which of the following is a relational operator:

3. Which of the following is a logical operator:

4. Identify the membership operator from the following:

c) both i & ii

5. Which one is a arithmetic operator:

d) Only ii 

6. What will be the correct output of the statement : >>>4//3.0

d) None of the above

7. What will be the correct output of the statement : >>> 4+2**2*10

8. Give the output of the following code:

>>> a,b=4,2

>>> a+b**2*10

9. Give the output of the following code:

>>> a,b = 4,2.5

>>> a-b//2**2

10. Give the output of the following code:

>>>a,b,c=1,2,3

>>> a//b**c+a-c*a

11. If a=1,b=2 and c= 3 then which statement will give the output as : 2.0 from the following:

a) >>>a%b%c+1

b) >>>a%b%c+1.0  

c) >>>a%b%c

b) >>>a%b%c+1.0 

12. Which statement will give the output as : True from the following :

a) >>>not -5

b) >>>not 5

c) >>>not 0 

d) >>>not(5-1)

13. Give the output of the following code:

>>>7*(8/(5//2))

14. Give the output of the following code:

>>>import math

>>> math.ceil(1.03)+math.floor(1.03)

15.What will be the output of the following code:

>>>math.fabs(-5.03)

16.Single line comments in python begin with……………….. symbol.

17.Which of the following are the fundamental building block of a python program.

a) Identifier 

b) Constant

c) Punctuators

18.The input() function always returns a value of ……………..type.

19.……….. function is used to determine the data type of a variable.

a) type( ) 

c) print( )

20.The smallest individual unit in a program is known as a……………

c) punctuator

d) identifier

FLOW OF EXECUTION

#Decision making statements in python Statement

21. Which of the following is not a decision making statement

a) if..else statement

b) for statement 

c) if-elif statement

d) if statement

22. …………loop is the best choice when the number of iterations are known.

b) do-while

d) None of these

23. How many times will the following code be executed.

while a>0:

print(“Bye”)

c) Infinite

24. What abandons the current iteration of the loop

a) continue

c) infinite

25. Find the output of the following python program

for i in range(1,15,4):

print(i, end=’,’)

c) 1,5,10,14

d) 1,5,9,13 

26. …………loop is the best when the number of iterations are not known.

27.In the nested loop ……………..loop must be terminated before the outer loop.

b) enclosing

28. …………..statement is an empty statement in python.

c) continue

29. How many times will the following code be executed

for i in range(1,15,5):

print(i,end=’,’)

d) infinite

30. Symbol used to end the if statement:

a) Semicolon(;)

b) Hyphen(-)

c) Underscore( _ )

d) colon(:)

String Methods and Built-in functions:

31. Which of the following is not a python legal string operation.

a) ‘abc’+’aba’

c) ‘abc’+3 

d) ‘abc’.lower()

32. Which of the following is not a valid string operation.

b) concatenation

c) Repetition

33. Which of the following is a mutable type.

34. What will be the output of the following code

str1=”I love Python”

strlen=len(str1)+5

print(strlen)

35. Which method removes all the leading whitespaces from the left of the string.

b) remove()

c) lstrip()

d) rstrip()

36. It returns True if the string contains only whitespace characters, otherwise returns False.

a) isspace()

c) islower()

d) isupper()

37. It converts uppercase letter to lowercase and vice versa of the given string.

a) lstrip()

b) swapcase()

c) istitle()

38.What will be the output of the following code.

Str=’Hello World! Hello Hello’

Str.count(‘Hello’,12,25)

39.What will be the output of the following code.

Str=”123456”

print(Str.isdigit())

40.What will be the output of the following code.

Str=”python 38”

print(Str.isalnum())

41.What will be the output of the following code.

Str=”pyThOn”

print(Str.swapcase())

42.What will be the output of the following code.

Str=”Computers”

print(Str.rstrip(“rs”))

a) Computer

b) Computers

c) Compute 

43.What will be the output of the following code.

Str=”This is Meera\’ pen”

44.How many times is the word ‘Python’ printed in the following statement.

s = ”I love Python”

for ch in s[3:8]:

print(‘Python’)

a) 11 times

d) 5 times 

45.Which of the following is the correct syntax of string slicing:

a) str_name[start:end] 

b) str_name[start:step]

c) str_name[step:end]

d) str_name[step:start]

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

A=”Virtual Reality”

print(A.replace(‘Virtual’,’Augmented’))

a) Virtual Augmented

b) Reality Augmented

c) Augmented Virtual

d) Augmented Reality 

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

print(“ComputerScience”.split(“er”,2))

a) [“Computer”,”Science”]

b) [“Comput”,”Science”] 

c) [“Comput”,”erScience”]

d) [“Comput”,”er”,”Science”]

48.Following set of commands are executed in shell, what will be the output?

>>>str=”hello”

>>>str[:2]

49.………..function will always return tuple of 3 elements.

c) partition()

50.What is the correct python code to display the last four characters of “Digital India”

a) str[-4:] 

c) str[*str]

d) str[/4:]

51. Given the list L=[11,22,33,44,55], write the output of print(L[: :-1]).

a) [1,2,3,4,5]

b) [22,33,44,55]

c) [55,44,33,22,11] 

d) Error in code

52. Which of the following can add an element at any index in the list?

a) insert( ) 

b) append( )

c) extend()

d) all of these

53. Which of the following function will return a list containing all the words of the given string?

54.Which of the following statements are True.

i) [1,2,3,4]>[4,5,6]

ii) [1,2,3,4]<[1,5,2,3]

iii) [1,2,3,4]>[1,2,0,3]

iv) [1,2,3,4]<[1,2,3,2]

b) i,iii,iv

c) i,ii,iii

55. If l1=[20,30] l2=[20,30] l3=[‘20’,’30’] l4=[20.0,30.0] then which of the following statements will not return ‘False’:

i) >>>l1==l2

ii) >>>l4>l1

iii) >>>l1>l2

iv) >>> l2==l2

b) i,ii,iii

c) i,iii,iv

56.>>>l1=[10,20,30,40,50]

>>>l2=l1[1:4]

What will be the elements of list l2:

a) [10,30,50]

b) [20,30,40,50]

c) [10,20,30]

d) [20,30,40] 

57.>>>l=[‘red’,’blue’]

>>>l = l + ‘yellow’

What will be the elements of list l:

a) [‘red’,’blue’,’yellow’]

b) [‘red’,’yellow’]

c) [‘red’,’blue’,’yellow’]

58.What will be the output of the following code:

>>>l=[1,2,3,4]

>>>m=[5,6,7,8]

>>>n=m+l

>>>print(n)

a) [1,2,3,5,6,7,8]

b) [1,2,3,4,5,6,7,8] 

c) [1,2,3,4][5,6,7,8]

59.What will be the output of the following code:

>>>m=l*2

>>>n=m*2

a) [1,2,3,4,1,2,3,4,1,2,3,4]

b) [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4] 

c) [1,2,3,4][4,5,6,7]

d) [1,2,3,4]

60.Match the columns: if

>>l=list(‘computer’)

 a) 1-b,2-d,3-a,4-c 

b) 1-c,2-b,3-a,4-d

c) 1-b,2-d,3-c,4-a

d) 1-d,2-a,3-c,4-b

61. If a list is created as

>>>l=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]] then what will be the output of the following statements:

>>>l[4][1]

b) ‘green’ 

d) ‘orange’

62.>>>l[8][0][2]

63.>>>l[-1]

a) [‘apple’,’green’]

b) [‘red’,’orange’]

c) [‘red’ ] 

d) [’orange’]

64.>>>len(l)

65.What will be the output of the following code:

>>>l1=[1,2,3]

>>>l1.append([5,6])

>>>l1

a) [1,2,3,5,6]

b) [1,2,3,[5,6]]

d) [1,2,3,[5,6]] 

66.What will be the output of the following code:

>>>l2=[5,6]

>>>l1.extend(l2)

a) [5,6,1,2,3]

b) [1,2,3,5,6] 

d) [1,2,3,6]

67. What will be the output of the following code:

>>>l1.insert(2,25)

a) [1,2,3,25]

b) [1,25,2,3]

c) [1,2,25,3] 

d) [25,1,2,3,6]

68. >>>l1=[10,20,30,40,50,60,10,20,10]

>>>l1.count(‘10’)

69.Which operators can be used with list?

c) both (i)&(ii) 

d) Arithmetic operator only

70.Which of the following function will return the first occurrence of the specified element in a list.

d) sorted()

MCQ Tuples and Dictionary:

71. Which of the statement(s) is/are correct.

a) Python dictionary is an ordered collection of items.

b) Python dictionary is a mapping of unique keys to values

c) Dictionary is mutable.

d) All of these. 

72. ………function is used to convert a sequence data type into tuple.

73. It tup=(20,30,40,50), which of the following is incorrect

a) print(tup[3])

b) tup[2]=55

c) print(max(tup))

d) print(len(tup))

74. Consider two tuples given below:

>>>tup1=(1,2,4,3)

>>>tup2=(1,2,3,4)

What will the following statement print(tup1<tup2)

75. Which function returns the number of elements in the tuple

d) count( )

76. Which function is used to return a value for the given key.

77.Keys of the dictionary must be

c) can be similar or unique

d) All of these

78. Which of the following is correct to insert a single element in a tuple .

79.Which of the following will delete key-value pair for key=’red’ form a dictionary D1

a) Delete D1(“red”)

b) del. D1(“red”)

c) del D1[“red”] 

80.Which function is used to remove all items form a particular dictionary.

a) clear( ) 

81.In dictionary the elements are accessed through

82.Which function will return key-value pairs of the dictionary

b) values( )

c) items( ) 

83.Elements in a tuple can be of ………….type.

a) Dissimilar

c) both i & ii 

84.To create a dictionary , key-value pairs are separated by…………….

85.Which of the following statements are not correct:

i) An element in a dictionary is a combination of key-value pair

ii) A tuple is a mutable data type

iii) We can repeat a key in dictionary

iv) clear( ) function is used to deleted the dictionary.

a) i,ii,iii

b) ii,iii,iv 

c) ii,iii,i

d) i,ii,iii,iv

86.Which of the following statements are correct:

i) Lists can be used as keys in a dictionary

ii) A tuple cannot store list as an element

iii) We can use extend() function with tuple.

iv) We cannot delete a dictionary once created.

b) ii,iii,iv

87.Like lists, dictionaries are……………..which mean they can be changed.

a) Mutable 

b) immutable

c) variable

88.To create an empty dictionary , we use

d) d= < >

89.To create dictionary with no items , we use

b) dict( ) 

90.What will be the output

>>>d1={‘rohit’:56,”Raina”:99}

>>>print(“Raina” in d1)

c) No output

91. Rahul has created the a tuple containing some numbers as

>>>t=(10,20,30,40)

now He want to add a new element 60 in the tuple, which statement he should use out of the given four.

a) >>>t+(60)

b) >>>t + 60

c)  >>>t + (60,) 

d) >>>t + (‘60’)

92. Rahul wants to delete all the elements from the tuple, which statement he should use

a) >>>del t

b) >>>t.clear()

c)  >>>t.remove()

d) >>>None of these

93.Rahul wants to display the last element of the tuple, which statement he should use

a) >>> t.display()

b) >>>t.pop()

c) >>>t[-1] 

d) >>>t.last()

94.Rahul wants to add a new tuple t1 to the tuple t, which statement he should use

a) >>>t+t1

b) >>>t.add(t1)

c) >>>t*t1

95. Rahul has issued a statement after that the tuple t is replace with empty tuple, identify the statement he had issued out of the following:

a) >>> del t

b) >>>t= tuple()

c) >>>t=Tuple()

d) >>>delete t

96. Rahul wants to count that how many times the number 10 has come:

a) >>>t.count(10) 

b) >>>t[10]

c) >>>count.t(10)

97. Rahul want to know that how many elements are there in the tuple t, which statement he should use out of the given four

a) >>>t.count()

b) >>>len(t) 

c) >>>count(t)

d) >>>t.sum()

98.>>>t=(1,2,3,4)

Write the statement should be used to print the first three elements 3 times

a) >>>print(t*3)

b) >>>t*3

c)  >>>t[:3]*3

d) >>>t+t

99. Match the output with the statement given in column A with Column B.

a) 1-b,2-c,3-d,4-a

b) 1-a,2-c,3-d,4-b

c) 1-c,2-d,3-a,4-a

d) 1-d,2-a,3-b,4-c

100. Write the output of the following code:

>>>d={‘name’:’rohan’,’dob’:’2002-03-11’,’Marks’:’98’}

>>>d1={‘name’:‘raj’)

>>>d1=d.copy()

>>>print(“d1 :”d1)

a) d1 : {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’}

b) d1 = {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’}

c) {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’}

d) (d1 : {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’})

Related Post

Class 12 computer science board question paper 2024 with answer key, python function arguments and parameters notes class 12 (positional, keyword, default), class 12 computer science notes topic wise.

CS-IP-Learning-Hub

CS-IP-Learning-Hub

Important Questions and Notes

Best 400+ MCQ on Python Revision Tour Class 12

Python Revision Tour Class 12

Python Revision Tour Class 12 Topic Wise MCQ

1. 140+ MCQ on Introduction to Python

2. 120 MCQ on String in Python

3. 100+ MCQ on List in Python

4. 50+ MCQ on Tuple in Python

5. 100+ MCQ on Flow of Control in Python

6. 60+ MCQ on Dictionary in Python

Important Links

100 practice questions on python fundamentals, 120+ mysql practice questions, 90+ practice questions on list, 50+ output based practice questions, 100 practice questions on string, 70 practice questions on loops, 120 practice questions of computer network in python, 70 practice questions on if-else, 40 practice questions on data structure, python functions mcq class 12 cs.

Computer Science Syllabus 2021-2022 .

Informatics Practices Syllabus 2021-2022

Class 12 Computer Science Chapter wise MCQ

Leave a Reply Cancel reply

CBSE Skill Education

Python Revision Tour 1 Class 12 MCQ

Teachers and Examiners ( CBSESkillEduction ) collaborated to create the Python Revision Tour 1 Class 12 MCQ. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.

1. An ordered set of instructions to be executed by a computer to carry out a specific task is called a ___________. a. Program  b. Instruction c. Code d. None of the above

2. Computers understand the language of 0s and 1s which is called __________. a. Machine language b. Low level language c. Both a) and b)  d. None of the above

3. A program written in a high-level language is called _________. a. Language b. Source code  c. Machine code d. None of the above

4. An interpreter read the program statements _________. a. All the source at a time b. One by one  c. Both a) and b) d. None of the above

5. Python is a __________. a. Low level language b. High level language  c. Machine level language d. All of the above

6. Python is __________. a. Open source language b. Free language c. Both a) and b)  d. None of the above

7. Python support __________. a. Compiler b. Interpreter  c. Assembler d. None of the above

8. Python programs are ___________. a. Easy to understand b. Clearly defined syntax c. Relatively simple structure d. All of the above 

9. Python is _________. a. Case – sensitive  b. Non case – sensitive c. Both a) and b) d. None of the above

10. Python is platform independent, meaning ___________. a. It can run various operating systems b. It can run various hardware platforms c. Both a) and b)  d. None of the above

11. Python uses indentation for __________. a. Blocks b. Nested Blocks c. Both a) and b)  d. None of the above

12. To write and run (execute) a Python program, we need to have a ___________. a. Python interpreter installed on the computer b. We can use any online python interpreter c. Both a) and b)  d. None of the above

13. The interpreter is also called python _______. a. Shell  b. Cell c. Program d. None of the above

14. To execute the python program we have to use __________. a. Interactive mode b. Script mode c. Both a) and b)  d. None of the above

15. __________ allows execution of individual statements instantaneously. a. Interactive mode  b. Script mode c. Both a) and b) d. None of the above

16. _________allows us to write more than one instruction in a file called Python source code. a. Interactive mode b. Script mode  c. Both a) and b) d. None of the above

17. To work in the interactive mode, we can simply type a Python statement on the ________ prompt directly. a. >>>  b. >> c. > d. None of the above

18. In the script mode, we can write a Python program in a ________, save it and then use the interpreter to execute it. a. Prompt b. File  c. Folder d. All of the above

19. By default the python extension is __________. a. .py  b. .ppy c. .pp d. .pyy

20. __________ are reserved words in python. a. Keyword  b. Interpreter c. Program d. None of the above

21. The rules for naming an identifier in Python are ________. a. Name should begin with an uppercase, lowercase or underscore b. It can be of any length c. It should not be a keyword d. All of the above 

22. To define variables in python _______ special symbols is not allowed. a. @ b. # and ! c. $ and % d. All of the above 

23. A variable in a program is uniquely identified by a name __________. a. Identifier  b. Keyword c. Code d. None of the above

24. Variable in python refers to an ________. a. Keyword b. Object  c. Alphabets d. None of the above

25. The variable message holds string type value and so its content is assigned within _________. a. Double quotes “” b. Single quotes ” c. Both a) and b)  d. None of the above

26. _________ must always be assigned values before they are used in expressions. a. Keyword b. Variable  c. Code d. None of the above

27. ___________ are used to add a remark or a note in the source code. a. Keyword b. Source c. Comment  d. None of the above

28. __________ are not executed by a python interpreter. a. Keyword b. Source c. Comment  d. None of the above

29. In python comments start from _______. a. #  b. @ c. % d. $

30. Python treats every value or data item whether numeric, string, or other type (discussed in the next section) as an _________. a. Object  b. Variable c. Keyword d. None of the above

31. _________ identifies the type of data values a variable can hold and the operations that can be performed on that data. a. Data type  b. Data base c. Both a) and b) d. None of the above

32. Number data type classified into ________. a. int b. float c. complex d. All of the above 

33. ________ data type is a subtype of integer a. Boolean  b. string c. list d. None of the above

34. A Python sequence is an ordered collection of items. a. Number b. Sequence  c. Both a) and b) d. None of the above

35. Sequence data type is classified into _________. a. Strings b. Lists c. Tuples d. All of the above 

36. __________ is a group of characters in python. a. Number b. String  c. Boolean d. All of the above

37. In the string data type you can store __________. a. Alphabets b. Digits c. Special character including space d. All of the above 

38. _________ is a sequence of items separated by commas and the items are enclosed in square brackets [ ]. a. List  b. Tuple c. String d. None of the above

39. __________ is a sequence of items separated by commas and items are enclosed in parenthesis ( ). a. List b. Tuple  c. String d. None of the above

40. _________ is an unordered collection of items separated by commas and the items are enclosed in curly brackets { }. a. List b. Set  c. String d. None of the above

41. ________ data type cannot have duplicate entries. a. List b. Set  c. String d. None of the above

42. None is a special data type with a single value. It is used to signify the absence of value in a situation. a. List b. Set c. String d. None 

43. ___________ in Python holds data items in key-value pairs. a. Dictionary  b. Set c. String d. None

44. Items in a dictionary are enclosed in __________. a. Parenthesis () b. Brackets [] c. Curly brackets {}  d. All of the above

45. In the dictionary every key is separated from its value using a _________. a. Colon (:)  b. Semicolon (;) c. Comma (,) d. All of the above

46. Variables whose values can be changed after they are created and assigned are called __________. a. Immutable b. Mutable  c. Both a) and b) d. None of the above

47. Variables whose values cannot be changed after they are created and assigned are called _________. a. Immutable  b. Mutable c. Both a) and b) d. None of the above

48. When we need uniqueness of elements and to avoid duplicacy it is preferable to use __________. a. List b. Set  c. Tuple d. All of the above

49.The values that the operators work on are called __________. a. Operands  b. Assignment c. Mathematical Operator d. All of the above

50. ____________ that are used to perform the four basic arithmetic operations as well as modular division, floor division and exponentiation. a. Arithmetic Operator  b. Logical Operator c. Relational Operator d. All of the above

51. __________ calculation on operands. That is, raise the operand on the left to the power of the operand on the right. a. Floor Division (//) b. Exponent (**)  c. Modulus (%) d. None of the above

52. _____________ compares the values of the operands on either side and determines the relationship among them. a. Arithmetic Operator b. Logical Operator c. Relational Operator  d. All of the above

53. _________ assigns or changes the value of the variable on its left. a. Relational Operator b. Assignment Operator  c. Logical Operator d. All of the above

54. Which one of the following logical operators is supported by python. a. and b. or c. not d. All of the above 

55. _________ operator is used to check both the operands are true. a. and  b. or c. not d. All of the above

56. ___________ are used to determine whether the value of a variable is of a certain type or not. a. Relational Operator b. Logical Operator c. Identity Operator  d. All of the above

57. ___________ can also be used to determine whether two variables are referring to the same object or not. a. Relational Operator b. Logical Operator c. Identity Operator  d. All of the above

58. Membership operators are used to check if a value is a member of the given sequence or not. a. Identity Operator b. Membership Operators  c. Relational Operators d. All of the above

59. An __________ is defined as a combination of constants, variables, and operators. a. Expressions  b. Precedence c. Both a) and b) d. None of the above

60. Evaluation of the expression is based on __________ of operators. a. Expressions b. Precedence  c. Both a) and b) d. None of the above

61. Example of membership operators. a. in b. not c. in d. All of the above 

62. Example of identity operators. a. is b. is not c. Both a) and b)  d. None of the above

63. In Python, we have the ____________ function for taking the user input. a. prompt() b. input()  c. in() d. None of the above

64. In Python, we have the ___________ function for displaying the output. a. prompt() b. output() c. print()  d. None of the above

65. ____________, also called type casting, happens when data type conversion takes place because the programmer forced it in the program. a. Explicit conversion  b. Implicit conversion c. Both a) and b) d. None of the above

66. __________, also known as coercion, happens when data type conversion is done automatically by Python and is not instructed by the programmer. a. Explicit conversion b. Implicit conversion  c. Both a) and b) d. None of the above

67. A programmer can make mistakes while writing a program, and hence, the program may not execute or may generate wrong output. The process of identifying and removing such mistakes, also known as __________. a. Bugs b. Errors c. Both a) and b)  d. None of the above

68. Identifying and removing bugs or errors from the program is also known as __________. a. Debugging  b. Mistakes c. Error d. None of the above

69. Which of the following errors occur in python programs. a. Syntax error b. Logical error c. Runtime error d. All of the above 

70. A _________ produces an undesired output but without abrupt termination of the execution of the program. a. Syntax error b. Logical error  c. Runtime error d. All of the above

71. A ___________ causes abnormal termination of the program while it is executing. a. Syntax error b. Logical error c. Runtime error  d. All of the above

72. Python is __________ language that can be used for a multitude of scientific and non-scientific computing purposes. a. Open – source b. High level c. Interpreter – based d. All of the above 

73. Comments are __________ statements in a program. a. Non – executable  b. Executable c. Both a) and b) d. None of the above

74. __________ is a user defined name given to a variable or a constant in a program. a. Keyword b. Identifier  c. Data type d. All of the above

75. The process of identifying and removing errors from a computer program is called _______. a. Debugging  b. Mistakes c. Error d. None of the above

76. The order of execution of the statements in a program is known as _______. a. Flow of control b. Flow of structure c. Flow of chart d. None of the above

77. Python supports ____________ control structures. a. Selection b. Repetition c. Both a) and b) d. None of the above

78 . Which one is the correct syntax of if statement in python. a. if condition:  statement(s) b. if condition statement(s) a. if (condition) statement(s) a. if condition then statement(s)

79. Number of ________ is dependent on the number of conditions to be checked. If the first condition is false, then the next condition is checked, and so on. a. Elese if b. If Else c. Elif  d. All of the above

80. The statements within a block are put inside __________. a. Single quotes b. Double quotes c. Curly brackets  d. Square brackets

81. Leading whitespace (spaces and tabs) at the beginning of a statement is called ________. a. Indentation  b. Repetition c. Code d. None of the above

82. This kind of repetition is also called __________ . a. Indentation b. Iteration  c. Both a) and b) d. None of the above

83. _________ constructs provide the facility to execute a set of statements in a program repetitively, based on a condition. a. Conditional Statement b. Looping Statement  c. Both a) and b) d. None of the above

84. The statements in a loop are executed again and again as long as particular logical condition remains true. a. For loop b. While loop c. Do-while loop d. All of the above 

85. What will happen when condition becomes false in the loop. a. Loop Execute b. Loop Terminates  c. Loop Repeat once again d. All of the above

86. What keyword would you add to an if statement to add a different condition? a. Else if b. Ifelse c. elif  d. None of the above

87. What is the output of the given below program? if 4 + 2 == 8: print(“Condition is True”) else: print(“Condition is False”) a. Condition is True b. Condition is False c. No Output d. Error

88. What is the output of the given below program? if 4 + 2 == 8: print(“Condition is True”) else: print(“Condition is False”) print(“Welcome”) a. Condition is True b. Condition is False  Welcome c. Condition is True Welcome d. Error

89. Find the output of the given Python program? a = 50 b = 60 if a < 50: print(“Condition is True”) if b <= 60: print(“Condition is True”) else: print(“Condition is False”) a. Condition is True  b. Condition is False c. No Output d. Error

90. What is the output of the given below program? a = 35 if a >= 35: print(“Condition is True”) if a <= 35: print(“Condition is True”) else: print(“Condition is False”) a. Condition is True b. Condition is True  Condition is True c. Condition is True Condition is False d. Condition is False Condition is True

91. Find the output of the given Python program? a, b, c = 1, 2, 3 if a > 0: if b < 2: print(“Welcome”) elif c >= 3: print(“Welcome to my School”) else: print(“New School”) a. Welcome b. Welcome to my School  c. New School d. Run time error

92. Find the output of the given Python program? a, b, c = 1, 2, 3 if a + b + c: print(“Condition is True”) else: print(“Condition is False”) a. Condition is True  b. Condition is False c. No Output d. Runt time error

93. What is the output of the given below program? b = 5 if a < b: print(“Condition is True”) else: print(“Condition is False”) a. Condition is True b. Condition is False c. NameError: name ‘a’ is not defined  d. No Output

94. What is the output of the given below program? a = b = true if (a and b): print(“Condition is True”) else: print(“Condition is False”) a. Condition is True b. Condition is False c. NameError: name ‘true’ is not defined  d. No Output

95. Which of the following is not a Python loop? a. for loop b. do-while loop  c. while loop d. None of the above

96. Regarding Python loops, which of the following statements is false? a. Loops are utilized to repeat specific actions. b. When several statements need to be performed repeatedly until the specified condition turns false, the while loop is employed.  c. When several statements need to be run repeatedly until the provided condition is true, a while loop is employed. d. List elements can be repeated through using a for loop.

97. What does range() function returns ? a. list of numbers. b. integer object. c. range object.  d. None of the above

98. Which of the following statements about Python loops is True? a. The keyword “end” should be used to end loops. b. The components of strings cannot be repeated over using a loop. c. You can break control from the current loop by using the keyword “break.”  d. To continue with the remaining statements inside the loop, use the keyword “continue.”

99. What will be the output of given Python code? a=7 b=0 while(a): if(a>5): b=b+a-2 a=a-1 else: break print(a) print(b) a. 4 7 b. 5 9  c. 4 10 d. 5 3

100. Which of the following is a valid for loop in Python? a. for i in range(5,5) b. for i in range(0,5) c. for i in range(0,5):  d. for i in range(5)

101. What will be the output of given Python code? str=”Welcome” sum=0 for n in str: if(n!=”l”): sum=sum+1 else: pass print(sum) a. 5 b. 6  c. 4 d. 9

102. How many times will the loop run? i=5 while(i>0): i=i-1 print (i) a. 5  b. 4 c. 3 d. 2

103. What will be the output of the following code? x = 12 for i in x: print(i) a. 12 b. 1 2 c. Error  d. None of the above

104. One loop may be used inside another loop using the Python programming language, which is known as? a. switch b. foreach c. nested  d. forall

105. Which of the following loop is work on the particular range in python ? a. while loop b. for loop  c. do while loop d. None of the above

106.What does break statement do? a. Stop  b. Repeat c. Skip d. Print

107. What does continue statement do? a. Print b. Stop c. Skip  d. Repeat

108. The if statement is used for _________. a. Selection making b. Decision making c. Both a) and b) d. None of the above

109. ___________ statement iterates over a range of values or a sequence. a. For  b. While c. Do-While d. None of the above

110. The statements within the body of the ________ must ensure that the condition eventually becomes false; otherwise, the loop will become an infinite loop, leading to a logical error in the program. a. For loop b. While loop  c. Do-While loop d. None of the above

111. The __________ statement immediately exits a loop, skipping the rest of the loop’s body. Execution continues with the statement immediately following the body of the loop. a. Break  b. Continue c. Exit d. None of the above

112. When a _________ statement is encountered, the control jumps to the beginning of the loop for the next iteration. a. Break b. Continue  c. Exit d. None of the above

113. A loop contained within another loop is called a __________. a. Another Loop b. Nested Loop  c. Next Loop d. None of the above

114. Python executes one statement to another statement from starting to end, this is known as ____________. a. Selection construct c. Sequential Construct  b. Iteration Construct d. All of the above

115. The sequence in which statements in a programme are executed is referred to as ___________. a. Constant flow c. Flow of control  b. Selection flow d. None of the above

116. There are _______ types of control structures that Python supports. a. 4 b. 3 c. 2  a. 1

117. Which of the following is a Python control structure? a. Iteration b. Selection c. Both a) and b)  d. None of the above

118. With the use of a __________ statement, the idea of decision-making or selection is implemented in programming. a. For loop b. While loop c. If & Else  d. Break & Continue

119. A program’s elif count depends on the _____________. a. Dependent on the condition  b. Dependent on the writing methods c. Dependent on the loop d. None of the above

120. ________ is an empty statement in Python. a. Fail b. Pass  c. Null d. None of the above

121. There are ______ spaces of indentation around a statement inside of “if.” a. 4  b. 8 c. 16 d. 20

122. If the condition is True, Amit wants to display “Welcome,” else “Welcome to my webpage” if the condition is false. Which of the following statements makes it easier to put this into practice? a. For Statement b. While Statement c. If & Else Statement  d. None of the above

123. In order to determine if a number is even or odd, Amit wants to develop a programme. He needs to have a solid understanding of _________ to do this. a. Conditional Statement  b. Break Statement c. Continue Statement d. None of the above

124. When if-elif statement is used in python? a. Only one condition b. Multiple condition  c. Never used d. None of the above

125. What is the purpose of “else” statement? a. It will execute when condition is false  b. It will execute when condition is true c. It will never execuite. d. Both a) and b)

Python Revision Tour II

Class 12 - computer science with python sumita arora, multiple choice questions.

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

  • integer position

Reason — The index is the numbered position of a letter in the string.

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

Reason — in is membership operator which returns True if a character or a substring exists in the given string else returns False.

The keys of a dictionary must be of ............... types.

  • any of these

Reason — Dictionaries are indexed by keys and its keys must be of any immutable type.

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

Reason — str[:2] here slicing operation begins from index 0 and ends at index 1. Hence the output will be 'he'.

What data type is the object below ? L = [1, 23, 'hello', 1]

Reason — A list can store a sequence of values belonging to any data type and they are depicted through square brackets.

What data type is the object below ? L = 1, 23, 'hello', 1

Reason — For creating a tuple, enclosing the elements inside parentheses is optional. Even if parentheses are omitted as shown here, still this statement will create a tuple.

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

Reason — Dictionaries are mutable with elements in the form of a key:value pair that associate keys to values.

What is the value of the following expression ? 3 + 3.00, 3**3.0

(6.0, 27.0)

  • (6.0, 9.00)
  • [6.0, 27.0]

Reason — The value of expression is in round brackets because it is tuple. 3 + 3.00 = 6.0 3**3.0 = 3 x 3 x 3 = 27.0

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 equals [1, 2, 4, 5] ?

  • AL[2:3] = []
  • AL[2:2] = []
  • AL.remove(3)

del AL[2] AL[2:3] = [] AL.remove(3)

Reason — del AL[2] — The del keyword deletes the element from the list AL from index 2. AL[2:3] = [] — The slicing of the list AL[2:3] begins at index 2 and ends at index 2. Therefore, the element at index 2 will be replaced by an empty list []. AL.remove(3) — The remove() function removes an element from the list AL from index 3."

Question 10

Which two lines of code are valid strings in Python ?

  • This is a string
  • 'This is a string'
  • (This is a string)
  • "This is a string"

'This is a string' "This is a string"

Reason — Strings are enclosed within single or double quotes.

Question 11

You have the following code segment :

What is the output of this code?

Reason — The + operator creates a new string by joining the two operand strings.

Question 12

Reason — string.upper() method returns a copy of the string converted to uppercase. The + operator creates a new string by joining the two operand strings.

Question 13

Which line of code produces an error ?

  • "one" + 'two'
  • "one" + "2"

Reason — The + operator has to have both operands of the same type either of number type (for addition) or of string type (for concatenation). It cannot work with one operand as string and one as a number.

Question 14

What is the output of this code ?

Reason — The + operator concatenates two strings and int converts it to integer type.

int("3" + "4") = int("34") = 34

Question 15

Which line of code will cause an error ?

Reason — Index 5 is out of range because list has 5 elements which counts to index 4.

Question 16

Which is the correct form of declaration of dictionary ?

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

  • Day = {1;'Monday', 2;'Tuesday', 3;'wednesday'}
  • Day = [1:'Monday', 2:'Tuesday', 3:'wednesday']
  • Day = {1'monday', 2'tuesday', 3'wednesday'}

Reason — The syntax of dictionary declaration is:

According this syntax, Day = {1:'Monday', 2:'Tuesday', 3:'wednesday'} is the correct answer.

Question 17

Identify the valid declaration of L:

L = ['Mon', '23', 'hello', '60.5']

Reason — A list can store a sequence of values belonging to any data type and enclosed in square brackets.

Question 18

Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect ?

  • print(T[1])
  • print(max(T))
  • print(len(T))

Reason — Tuples are immutable. Hence we cannot perform item-assignment in tuples.

Fill in the Blanks

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

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

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

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

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

Tuples or Strings are not mutable while lists are.

Using list() function, you can make a true copy of a list.

The pop() function is used to remove an item from a list/dictionary.

The del statement can remove an individual item or a slice from a list.

The clear() function removes all the elements of a list/dictionary.

Creating a tuple from a set of values is called packing .

Creating individual values from a tuple's elements is called unpacking .

The keys() method returns all the keys in a dictionary.

The values() function returns all values from Key : value pair of a dictionary.

The items() function returns all the Key : value pairs as (key, value) sequences.

True/False Questions

Do both the following represent the same list. ['a', 'b', 'c'] ['c', 'a', 'b']

Reason — Lists are ordered sequences. In the above two lists, even though the elements are same, they are at different indexes (i.e., different order). Hence, they are two different lists.

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

Reason — A list can store any data types and even list can contain another list as element.

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

Reason — The list can be of any size.

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

Reason — A list is a standard data type of python that can store a sequence of values belonging to any data type.

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

Reason — List can have duplicate values.

The keys of a dictionary must be of immutable types.

Reason — Dictionaries are indexed by keys. Hence its keys must be of any non-mutable type.

You can combine a numeric value and a string by using the + symbol.

Reason — The + operator has to have both operands of the same type either of number type (for addition) or both of string type (for concatenation). It cannot work with one operand as string and one as a number.

The clear( ) removes all the elements of a dictionary but does not delete the empty dictionary.

Reason — The clear() method removes all items from the dictionary and the dictionary becomes empty dictionary post this method. del statement removes the complete dictionary as an object.

The max( ) and min( ) when used with tuples, can work if elements of the tuple are all of the same type.

Reason — Tuples should contain same type of elements for max() and min() method to work.

A list of characters is similar to a string type.

Reason — In Python, a list of characters and a string type are not similar. Strings are immutable sequences of characters, while lists are mutable sequences that can contain various data types. Lists have specific methods and behaviors that differ from strings, such as append(), extend(), pop() etc.

For any index n, s[:n] + s[n:] will give you original string s.

Reason — s[:n] — The slicing of a string starts from index 0 and ends at index n-1. s[n:] — The slicing of a string starts from index n and continues until the end of the string. So when we concatenate these two substrings we get original string s.

A dictionary can contain keys of any valid Python types.

Reason — The keys of a dictionary must be of immutable types.

Assertions and Reasons

Assertion. Lists and Tuples are similar sequence types of Python, yet they are two different data types.

Reason. List sequences are mutable and Tuple sequences are immutable.

Both Assertion and Reason are true and Reason is the correct explanation of Assertion.

Explanation Lists and tuples are similar sequence types in python, but they are distinct data types. Both are used to store collections of items, but they have different properties and use cases. Lists are mutable, meaning you can add, remove, or modify elements after the list is created. Tuples, on the other hand, are immutable, meaning once a tuple is created, its contents cannot be changed.

Assertion. Modifying a string creates another string internally but modifying a list does not create a new list.

Reason. Strings store characters while lists can store any type of data.

Both Assertion and Reason are true but Reason is not the correct explanation of Assertion.

Explanation In Python, strings are immutable, meaning once they are created, their contents cannot be changed. Whenever we modify a string, python creates a new string object to hold the modified contents, leaving the original string unchanged. On the other hand, lists in python are mutable, meaning we can modify their contents after they have been created. When we modify a list, python does not create a new list object. Instead, it modifies the existing list object in place. Strings are sequences of characters, and each character in a string can be accessed by its index. Lists, on the other hand, can store any type of data, including integers, floats, strings.

Reason. Strings are immutable types while lists are mutable types of python.

Explanation In Python, strings are immutable, meaning once they are created, their contents cannot be changed. Whenever we modify a string, python creates a new string object to hold the modified contents, leaving the original string unchanged. On the other hand, lists in python are mutable, meaning we can modify their contents after they have been created. When we modify a list, python does not create a new list object. Instead, it modifies the existing list object in place.

Assertion. Dictionaries are mutable, hence its keys can be easily changed.

Reason. Mutability means a value can be changed in place without having to create new storage for the changed value.

Assertion is false but Reason is true.

Explanation Dictionaries are indexed by keys and each key must be immutable and unique. However, the dictionary itself is mutable, meaning that we can add, remove, or modify key-value pairs within the dictionary without changing the identity of the dictionary object itself. Mutability refers to the ability to change a value in place without creating a new storage location for the changed value.

Assertion. Dictionaries are mutable but their keys are immutable.

Reason. The values of a dictionary can change but keys of dictionary cannot be changed because through them data is hashed.

Explanation A dictionary is a unordered set of key : value pairs and are indexed by keys. The values of a dictionary can change but keys of dictionary cannot be changed because through them data is hashed. Hence dictionaries are mutable but keys are immutable and unique.

Assertion. In Insertion Sort, a part of the array is always sorted.

Reason. In Insertion sort, each successive element is picked and inserted at an appropriate position in the sorted part of the array.

Explanation Insertion sort is a sorting algorithm that builds a sorted list, one element at a time from the unsorted list by inserting the element at its correct position in sorted list. In Insertion sort, each successive element is picked and inserted at an appropriate position in the previously sorted array.

Type A: Short Answer Questions/Conceptual Questions

What is the internal structure of python strings ?

Strings in python are stored as individual characters in contiguous memory locations, with two-way index for each location. The index (also called subscript) is the numbered position of a letter in the string. Indices begin 0 onwards in the forward direction up to length-1 and -1,-2, .... up to -length in the backward direction. This is called two-way indexing.

Write a python script that traverses through an input string and prints its characters in different lines - two characters per line.

Discuss the utility and significance of Lists, briefly.

A list is a standard data type of python that can store a sequence of values belonging to any type. Lists are mutable i.e., we can change elements of a list in place. Their dynamic nature allows for flexible manipulation, including appending, inserting, removing, and slicing elements. Lists offer significant utility in data storage, iteration, and manipulation tasks.

What do you understand by mutability ? What does "in place" task mean ?

Mutability means that the value of an object can be updated by directly changing the contents of the memory location where the object is stored. There is no need to create another copy of the object in a new memory location with the updated values. Examples of mutable objects in python include lists, dictionaries. In python, "in place" tasks refer to operations that modify an object directly without creating a new object or allocating additional memory. For example, list methods like append(), extend(), and pop() perform operations in place, modifying the original list, while string methods like replace() do not modify the original string in place but instead create a new string with the desired changes.

Start with the list [8, 9, 10]. Do the following using list functions:

  • Set the second entry (index 1) to 17
  • Add 4, 5 and 6 to the end of the list
  • Remove the first entry from the list
  • Sort the list
  • Double the list
  • Insert 25 at index 3

listA = [8, 9, 10]

  • listA[1] = 17
  • listA.extend([4, 5, 6])
  • listA.pop(0)
  • listA.sort()
  • listA = listA * 2
  • listA.insert(3, 25)

What's a[1 : 1] if a is a string of at least two characters ? And what if string is shorter ?

a[x:y] returns a slice of the sequence from index x to y - 1. So, a[1 : 1] will return an empty list irrespective of whether the list has two elements or less as a slice from index 1 to index 0 is an invalid range.

What are the two ways to add something to a list ? How are they different ?

The two methods to add something to a list are:

append method — The syntax of append method is list.append(item) .

extend method — The syntax of extend method is list.extend(<list>) .

The difference between the append() and extend() methods in python is that append() adds one element at the end of a list, while extend() can add multiple elements, given in the form of a list, to a list.

append method:

Output — [10, 12, 14, 16]

extend method:

Output — ['a', 'b', 'c', 'd', 'e']

What are the two ways to remove something from a list? How are they different ?

The two ways to remove something from a list are:

pop method — The syntax of pop method is List.pop(<index>) .

del statement — The syntax of del statement is

The difference between the pop() and del is that pop() method is used to remove single item from the list, not list slices whereas del statement is used to remove an individual item, or to remove all items identified by a slice.

pop() method:

Output — 'k'

del statement:

Output — [1, 2, 5]

What is the difference between a list and a tuple ?

In the Python shell, do the following :

  • Define a variable named states that is an empty list.
  • Add 'Delhi' to the list.
  • Now add 'Punjab' to the end of the list.
  • Define a variable states2 that is initialized with 'Rajasthan', 'Gujarat', and 'Kerala'.
  • Add 'Odisha' to the beginning of the list states2.
  • Add 'Tripura' so that it is the third state in the list states2.
  • Add 'Haryana' to the list states2 so that it appears before 'Gujarat'. Do this as if you DO NOT KNOW where 'Gujarat' is in the list. Hint. See what states2.index("Rajasthan") does. What can you conclude about what listname.index(item) does ?
  • Remove the 5th state from the list states2 and print that state's name.
  • states = []
  • states.append('Delhi')
  • states.append('Punjab')
  • states2 = ['Rajasthan', 'Gujarat', 'Kerala']
  • states2.insert(0,'Odisha')
  • states2.insert(2,'Tripura')
  • a = states2.index('Gujarat') states2.insert(a - 1,'Haryana')
  • b = states2.pop(4) print(b)

Discuss the utility and significance of Tuples, briefly.

Tuples are used to store multiple items in a single variable. It is a collection which is ordered and immutable i.e., the elements of the tuple can't be changed in place. Tuples are useful when values to be stored are constant and need to be accessed quickly.

If a is (1, 2, 3)

  • what is the difference (if any) between a * 3 and (a, a, a) ?
  • Is a * 3 equivalent to a + a + a ?
  • what is the meaning of a[1:1] ?
  • what is the difference between a[1:2] and a[1:1] ?
  • a * 3 ⇒ (1, 2, 3, 1, 2, 3, 1, 2, 3) (a, a, a) ⇒ ((1, 2, 3), (1, 2, 3), (1, 2, 3)) So, a * 3 repeats the elements of the tuple whereas (a, a, a) creates nested tuple.
  • Yes, both a * 3 and a + a + a will result in (1, 2, 3, 1, 2, 3, 1, 2, 3).
  • This colon indicates (:) simple slicing operator. Tuple slicing is basically used to obtain a range of items. tuple[Start : Stop] ⇒ returns the portion of the tuple from index Start to index Stop (excluding element at stop). a[1:1] ⇒ This will return empty list as a slice from index 1 to index 0 is an invalid range.
  • Both are creating tuple slice with elements falling between indexes start and stop. a[1:2] ⇒ (2,) It will return elements from index 1 to index 2 (excluding element at 2). a[1:1] ⇒ () a[1:1] specifies an invalid range as start and stop indexes are the same. Hence, it will return an empty list.

What is the difference between (30) and (30,) ?

a = (30) ⇒ It will be treated as an integer expression, hence a stores an integer 30, not a tuple. a = (30,) ⇒ It is considered as single element tuple since a comma is added after the element to convert it into a tuple.

Write a Python statement to declare a Dictionary named ClassRoll with Keys as 1, 2, 3 and corresponding values as 'Reena', 'Rakesh', 'Zareen' respectively.

Why is a dictionary termed as an unordered collection of objects ?

A dictionary is termed as an unordered collection of objects because the elements in a dictionary are not stored in any particular order. Unlike string, list and tuple, a dictionary is not a sequence. For a dictionary, the printed order of elements is not the same as the order in which the elements are stored.

What type of objects can be used as keys in dictionaries ?

Keys of a dictionary must be of immutable types such as

  • a Python string
  • a tuple (containing only immutable entries)

Though tuples are immutable type, yet they cannot always be used as keys in a dictionary. What is the condition to use tuples as a key in a dictionary ?

For a tuple to be used as a key in a dictionary, all its elements must be immutable as well. If a tuple contains mutable elements, such as lists, sets, or other dictionaries, it cannot be used as a key in a dictionary.

Dictionary is a mutable type, which means you can modify its contents ? What all is modifiable in a dictionary ? Can you modify the keys of a dictionary ?

Yes, we can modify the contents of a dictionary. Values of key-value pairs are modifiable in dictionary. New key-value pairs can also be added to an existing dictionary and existing key-value pairs can be removed. However, the keys of the dictionary cannot be changed. Instead we can add a new key : value pair with the desired key and delete the previous one. For example:

Explanation

d is a dictionary which contains one key-value pair. d[2] = 2 adds new key-value pair to d. d[1] = 3 modifies value of key 1 from 1 to 3. d[3] = 2 adds new key-value pair to d. del d[2] deletes the key 2 and its corresponding value.

Question 19

How is del D and del D[<key>] different from one another if D is a dictionary ?

del D deletes the entire dictionary D. After executing del D , the variable D is no longer defined, and any attempt to access D will result in a NameError . del D[<key>] deletes the key-value pair associated with the specified key from the dictionary D . After executing del D[<key>] , the dictionary D still exists, but the specified key and its corresponding value are removed from the dictionary.

For example:

Question 20

Create a dictionary named D with three entries, for keys 'a', 'b' and 'c'. What happens if you try to index a nonexistent key (D['d']) ? What does python do if you try to assign to a nonexistent key d. (e.g., D['d'] = 'spam') ?

  • In this example, the dictionary D does not contain the key 'd'. Therefore, attempting to access this key by D['d'] results in a KeyError because the key does not exist in the dictionary.
  • If we try to assign a value to a nonexistent key in a dictionary, python will create that key-value pair in the dictionary. In this example, the key 'd' did not previously exist in the dictionary D. When we attempted to assign the value 'spam' to the key 'd', python created a new key-value pair 'd': 'spam' in the dictionary D.

Question 21

What is sorting ? Name some popular sorting techniques.

Sorting refers to arranging elements of a sequence in a specific order — ascending or descending.

Sorting Techniques are as follows :

  • Bubble Sort
  • Insertion Sort
  • Selection Sort

Question 22

Discuss Bubble sort and Insertion sort techniques.

Bubble Sort : In Bubble sort, the adjoining values are compared and exchanged if they are not in proper order. This process is repeated until the entire array is sorted.

Insertion Sort : Insertion sort is a sorting algorithm that builds a sorted list one element at a time from the unsorted list by inserting the element at its correct position in sorted list.

Type B: Application Based Questions

Question 1(a).

What will be the output produced by following code fragments ?

str(123) converts the number 123 to string and stores in y so y becomes "123". "hello" * 3 repeats "hello" 3 times and stores it in x so x becomes "hellohellohello".

"hello" + "world" concatenates both the strings so x becomes "helloworld". As "helloworld" contains 10 characters so len(x) returns 10.

Question 1(b)

The code concatenates three strings "hello", "to Python", and "world" into the variable x . Then, it iterates over each character in x using a for loop. For each character, it assigns it to the variable y and prints y followed by a colon and space, all on the same line due to the end=" " parameter.

Question 1(c)

print(x[:2], x[:-2], x[-2:]) — x[:2] extracts the substring from the beginning of x up to index 1, resulting in "he". x[:-2] extracts the substring from the beginning of x up to the third last character, resulting in "hello wor". x[-2:] extracts the substring from the last two characters of x until the end, resulting in "ld". Hence, output of this line becomes he hello wor ld

print(x[6], x[2:4]) — x[6] retrieves the character at index 6, which is 'w'. x[2:4] extracts the substring from index 2 up to index 3, resulting in "ll". Hence, output of this line becomes w ll

print(x[2:-3], x[-4:-2]) — x[2:-3] extracts the substring from index 2 up to the fourth last character, resulting in "llo wo". x[-4:-2] extracts the substring from the fourth last character to the third last character, resulting in "or". Hence, output of this line becomes llo wo or

Write a short Python code segment that adds up the lengths of all the words in a list and then prints the average (mean) length.

  • The code prompts the user to enter a list of words and assigns it to the variable word_list .
  • We iterate over word_list using for loop. Inside the loop, length of each word gets added to total_length variable.
  • Average length is calculated by dividing total_length by the number of words in word_list .

Predict the output of the following code snippet ?

The slicing notation a[start:stop:step] extracts a portion of the list from index start to stop-1 with a specified step. In the slicing part a[3:0:-1] :

  • start is 3, which corresponds to the element with value 4.
  • stop is 0, but as element at stop index is excluded so slicing goes up to index 1.
  • step is -1, indicating that we want to step backward through the list.

Putting it together:

This extracts elements from index 3 to (0+1) in reverse order with a step of -1.

The output of the code will be:

Question 4(a)

Predict the output of the following code snippet?

  • arr is initialised as a list with elements [1, 2, 3, 4, 5, 6].
  • for loop iterates over the indices from 1 to 5. For each index i , it assigns the value of arr[i] to arr[i - 1] , effectively shifting each element one position to the left. After this loop, the list arr becomes [2, 3, 4, 5, 6, 6] .
  • Second for loop iterates over the indices from 0 to 5 and prints each element of the list arr without newline characters because of end="" parameter. Then it prints the elements of the modified list arr , resulting in 234566 .

Question 4(b)

  • Numbers is a list containing the numbers 9, 18, 27, and 36.
  • The outer for loop iterates over each element in the list Numbers .
  • The inner loop iterates over the range from 1 to the remainder of Num divided by 8. For example, if Num is 9, the range will be from 1 to 1 (9 % 8 = 1). If Num is 18, the range will be from 1 to 2 (18 % 8 = 2), and so on. Then it prints the value of N, followed by a "#", and ensures that the output is printed on the same line by setting end=" ".
  • After both loops, it prints an empty line, effectively adding a newline character to the output.

Question 5(a)

Find the errors. State reasons.

t[0] = 6 will raise a TypeError as tuples are immutable (i.e., their elements cannot be changed after creation).

Question 5(b)

There are no errors in this python code. Lists in python can contain elements of any type. As lists are mutable so t[0] = 6 is also valid.

Question 5(c)

t[4] = 6 will raise an error as we are trying to change the value at index 4 but it is outside the current range of the list t . As t has 3 elements so its indexes are 0, 1, 2 only.

Question 5(d)

t[0] = "H" will raise an error because strings in python are immutable, meaning we cannot change individual characters in a string after it has been created. Therefore, attempting to assign a new value to t[0] will result in an error.

Question 5(e)

The errors in this code are:

  • In the list [Amar, Shveta, Parag] , each element should be enclosed in quotes because they are strings.
  • The equality comparison operator is '==' instead of = for checking equality.
  • if statement should be lowercase.

Assuming words is a valid list of words, the program below tries to print the list in reverse. Does it have an error ? If so, why ? (Hint. There are two problems with the code.)

There are two issue in range(len(words), 0, -1) :

  • The start index len(words) is invalid for the list words as it will have indexes from 0 to len(words) - 1 .
  • The end index being 0 means that the last element of the list is missed as the list will be iterated till index 1 only.

The corrected python code is :

What would be the output of following code if ntpl = ("Hello", "Nita", "How's", "life ?") ?

ntpl is a tuple containing 4 elements. The statement (a, b, c, d) = ntpl unpacks the tuple ntpl into the variables a, b, c, d. After that, the values of the variables are printed.

The statement ntpl = (a, b, c, d) forms a tuple with values of variables a, b, c, d and assigns it to ntpl. As these variables were not modified, so effectively ntpl still contains the same values as in the first statement.

ntpl[0] ⇒ "Hello" ∴ ntpl[0][0] ⇒ "H"

ntpl[1] ⇒ "Nita" ∴ ntpl[1][1] ⇒"i"

ntpl[0][0] and ntpl[1][1] concatenates to form "Hi". Thus ntpl[0][0]+ntpl[1][1], ntpl[1] will return "Hi Nita ".

What will be the output of the following code ?

Tuples can be declared with or without parentheses (parentheses are optional). Here, tuple_a is declared without parentheses where as tuple_b is declared with parentheses but both are identical. As both the tuples contain same values so the equality operator ( == ) returns true.

What will be the output of the following code snippet ?

In the given python code snippet, id1 and id2 will point to two different objects in memory as del rec deleted the original dictionary whose id is stored in id1 and created a new dictionary with the same contents storing its id in id2 . However, id1 == id2 will compare the contents of the two dictionaries pointed to by id1 and id2 . As contents of both the dictionaries are same hence it returns True . If in this code we add another line print(id1 is id2) then this line will print False as id1 and id2 point to two different dictionary objects in memory.

Write the output of the code given below :

A dictionary my_dict with two key-value pairs, 'name': 'Aman' and 'age': 26 is initialized. Then updates the value associated with the key 'age' to 27. Then adds a new key-value pair 'address': 'Delhi' to the dictionary my_dict . The items() method returns all of the items in the dictionary as a sequence of (key, value) tuples. In this case, it will print [('name', 'Aman'), ('age', 27), ('address', 'Delhi')].

Write a method in python to display the elements of list thrice if it is a number and display the element terminated with '#' if it is not number.

For example, if the content of list is as follows :

The output should be 414141 DROND# GIRIRAJ# 131313 ZAR#

  • The code prompts the user to enter the elements of the list separated by spaces and stores the input as a single string in the variable my_list .
  • Then splits the input string my_list into individual elements and stores them in a new list called new_list .
  • Then for loop iterates over each element in the new_list.
  • The isdigit() method is used to check if all characters in the string are digits. If it's true (i.e., if the element consists only of digits), then it prints the element concatenated with itself three times. Otherwise, if the element contains non-digit characters, it prints the element concatenated with the character '#'.

Name the function/method required to

(i) check if a string contains only uppercase letters.

(ii) gives the total length of the list.

(i) isupper() method is used to check if a string contains only uppercase letters.

(ii) len() gives the total length of the list.

  • An empty dictionary named my_dict is initialized.
  • my_dict[(1,2,4)] = 8, my_dict[(4,2,1)] = 10, my_dict[(1,2)] = 12 these lines assign values to the dictionary my_dict with keys as tuples. Since tuples are immutable, so they can be used as keys in the dictionary.
  • The for loop iterates over the keys of the dictionary my_dict . Inside the loop, the value associated with each key k is added to the variable sum .
  • sum and my_dict are printed.

Type C: Programming Practice/Knowledge based Questions

Write a program that prompts for a phone number of 10 digits and two dashes, with dashes after the area code and the next three numbers. For example, 017-555-1212 is a legal input. Display if the phone number entered is valid format or not and display if the phone number is valid or not (i.e., contains just the digits and dash at specific places).

Write a program that should prompt the user to type some sentence(s) followed by "enter". It should then print the original sentence(s) and the following statistics relating to the sentence(s):

  • Number of words
  • Number of characters (including white-space and punctuation)
  • Percentage of characters that are alpha numeric
  • Assume any consecutive sequence of non-blank characters in a word.

Write a program that takes any two lists L and M of the same size and adds their elements together to form a new list N whose elements are sums of the corresponding elements in L and M. For instance, if L = [3, 1, 4] and M = [1, 5, 9], then N should equal [4, 6, 13].

Write a program that rotates the elements of a list so that the element at the first index moves to the second index, the element in the second index moves to the third index, etc., and the element in the last index moves to the first index.

Write a short python code segment that prints the longest word in a list of words.

Write a program that creates a list of all the integers less than 100 that are multiples of 3 or 5.

Define two variables first and second so that first = "Jimmy" and second = "Johny". Write a short python code segment that swaps the values assigned to these two variables and prints the results.

Write a python program that creates a tuple storing first 9 terms of Fibonacci series.

Create a dictionary whose keys are month names and whose values are the number of days in the corresponding months.

(a) Ask the user to enter a month name and use the dictionary to tell them how many days are in the month.

(b) Print out all of the keys in alphabetical order.

(c) Print out all of the months with 31 days.

(d) Print out the (key-value) pairs sorted by the number of days in each month.

Write a function called addDict(dict1, dict2) which computes the union of two dictionaries. It should return a new dictionary, with all the items in both its arguments (assumed to be dictionaries). If the same key appears in both arguments, feel free to pick a value from either.

Write a program to sort a dictionary's keys using Bubble sort and produce the sorted keys as a list.

Write a program to sort a dictionary's values using Bubble sort and produce the sorted values as a list.

Coding Python

Python Revision Tour Worksheet Class 12

Multiple Choice Questions:  (20 x 1=20)

1. What will be the output of the following Python code?

from math import factorial print (math.factorial (5))

(a) 120 (b) Nothing is printed (c) Error, method factorial doesn’t exist in math module (d) Error, the statement should be: print(factorial(5))

2. What is the order of namespaces in which Python looks for an identifier? (a) Python first searches the global namespace, then the local namespace and finally the built-in namespace (b) Python first searches the local namespace, then the global namespace and finally the built-in namespace (c) Python first searches the built-in namespace, then the global namespace and finally the local namespace (d) Python first searches the built-in namespace, then the local namespace and finally the gloab namespace

3. Which of the following is not a valid namespace? (a) Global namespace (b) Public namespace (c) Built-in namespace (d) Local namespace

4. What will be the output of the following Python code?

#modules def change (a): b=[x * 2 for x in a] print (b)

#module 2 def change (a): b= (x*x for x in a) print (b)

from module import change from module2 import change #main s = [1, 2, 3] change (s)

(a) [2, 4, 6] (b) [1, 4, 9] (c) [2, 4, 6] [1, 4, 9] (d) There is a name cash

5. What is the output of the function shown below (random module has already been imported)?

random.choice(‘sun’)

(a) sun (b) u (c) either s, u or n (d) error

6. What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code?

import random AR = [ 20, 30, 40, 50, 60, 70] FROM = random.randint (1, 3) TO = random.randint (2, 4) for K in range (FROM, TO+1): print (AR(K), end = “#”)

(a) 10#40#70# (b) 30#40#50# (c) 50#60#70# (d) 40#50#70#

7. Which of the statements is used to import all names from a module into the current calling module? (a) import (b) from (c) import * (d) dir()

8. Which of the variables tells the interpreter where to locate the module files imported into a program? (a) local (b) import variable (c) PYTHONPATH (d) current

9. Which of the following date class function returns the current system date? (a) day() (b) today() (c) month() (d) year()

10. What is the range of values that random.random() can return? (a) [0.0, 1.0] (b) (0.0, 1.0] (c) (0.0, 1.0) (d) [0.0, 1.0)

11. A .py file containing constants/variables, classes, functions etc. related to a particular task and can be used in other programs is called (a) module (b) library (c) classes (d) documentation

12. The collection of modules and packages that together cater to a specific type of applications or requirements, is called ____. (a) module (b) library (c) classes (d) documentation

13. An independent triple quoted string given inside a module, containing documentation related information is a ____. (a) Documentation string (b) docstring (c) dstring (d) stringdoc

14. The help <module> statement displays ____ from a module. (a) constants (b) functions (c) classes (d) docstrings

15. Which command(s) modifies the current namespace with the imported object name? (a) import <module> (b) import <module1>, <module2> (c) from <module> import <object> (d) from <module> import *

16. Which command(s) creates a separate namespace for each of the imported module? (a) import <module> (b) import <module1>, <module2> (c) from <module> import <object> (d) from <module> import *

17. Which of the following random module functions generates a floating point number? (a) random() (b) randint() (c) uniform() (d) all of these

18. Which of the following random module functions generates an integer? (a) random() (b) randint() (c) uniform() (d) all of these

19. Which file must be a part of a folder to be used as a Python package? (a) package.py (b) __init__.py (c) __package__.py (d) __module.py__

20. A Python module has ___ extension. (a) .mod (b) .imp (c).py (d) .mpy

Fill in the Blanks:(5 x 1=5)

21. Commonly-used modules that contain source code for generic needs are called _____.

22. A Python _____ is a directory of Python module(s).

23   We can use any Python source file as a module by executing an _____ statement

24._______ are used to distinguish between different sections of a program.

25. A _____ is a separately saved unit whose functionality can be reused at will.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

python revision tour mcq

+918076665624

Learnpython4cbse, inspiring success, click here for, vide o tutorial @ youtube channel supernova, there’s nothing here....

We can’t find the page you’re looking for. Check the URL, or head back home.

python revision tour mcq

logo

Have an account?

pencil-icon

Python Revision Tour - II

User image

15 questions

Player avatar

Introducing new   Paper mode

No student devices needed.   Know more

If you want to write code to check whether the given no. is divisible by 3. what condition will you write with if ( ) in the code written below

Identify the suitable construct to make the following Program

Identify the type of structure in the following code snippet

nested if else

(5==5) or (3==1) will give result

(4==5) or (3==3) will give result

(6) and (37==8) will give result

(8==8) and 6 will give result

(8!=8) and 6 will give result

(8) and 6==6 will give result

'Classroom Diary' or "Python" will produce result

Classroom Diary

( "Learn Python" and " " ) will produce result

Learn Python

( "Learn Python" and 2<3 ) will produce result

not ( "Learn Python" and 2<3 ) will produce result

In the expression x= 5/2 .....Data type of x is

Data type of "TRUE" is

Explore all questions with a free account

Google Logo

Continue with email

Continue with phone

Python revision Tour || Multiple Choice Questions || Class 12

1. Which of the following is an invalid variable?

(a) my_day_2

(b) 2nd_day

2. Which of the following is not a keyword?

(c) nonlocal

3. Which of the following cannot be a variable?

(a) __init__

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

(b) Dictionary

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

(d) none of these

6. What will be the value of the expression?

14 +13 % 15

7. Evaluate the expression given below if A = 16 and B = 15.

8. What is the value of x?

x = int(13.25 4/2)

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) <<, >>

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\test.txt

(a) print("hello\example\test.txt")

(b) print("hello\\example\\test.txt")

(c) print("hello\"example \"test.txt")

(d) print("hello"\example"\test.txt")

13. Which value type does input() return?

(a) Boolean

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

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

Select all of the function calls that result in this output

print('''Eina

(b) print('''EinaMinaDika''')

(c) print('Eina\nMina\nDika')

print('Eina

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

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

(a) position

(b) integer position

(d) location

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

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]

>>>

21. What data type is the object below?

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

(b) dictionary

22. What data type is the object below?

L = 1, 23, 'hello', 1

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

(d) dictionary

24. What is the value of the following expression?

3 + 3.00, 3**3.0

(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) a.remove(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

28. You have the following code segment

print(String1 + string2.upper())

(b) MY Work

(d) My Work

29. Which line of code produces an error?

(a) "one" + 'two'

(c) "one"+ "2"

(d) '1' + 2

30. What is the output of this code?

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

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])

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]

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

(c) hello_rsp1

(d) 2 hundred

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

(c) 100+200

36. Which amongst the following is a mutable data type in Python?

37. pow() function belongs to which library?

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".

(c) New Delhi

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

a = [5, 10, 15, 20, 25]

i = a[1] + 1

j = a[2] +1

print (i, j, m)

(a) 11 15 16

(b) 11 16 15

(c) 11 15 15

(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()

(c) substring()

(d) random()

43. What is the output of the following?

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

for i in d:

44. What is the output of the following?

for i in x:

(d) infinite loop

45. Which arithmetic operators cannot be used with strings?

(d) all of the above

46. What will be the output when the following code is executed?

>>> str1="helloworld"

>>> stri[:-1]

(a) dlrowolleh

(d) helloworld

47. What is the output of the following statement?

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

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'}

(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]

You can help us by Clicking on ads. ^_^ Please do not send spam comment : )

python revision tour mcq

thnak you, is it 2021-22?

bro i specially came to comment here..why are most of the answers given here in this MCQ part are wrong...fill in the blanks and true or false, both were fine..plz look into it

EDIT: I just noticed a pattern, the answers in itself aren't wrong..its just that, the numbering is wrong. For eg- In Q36. the answer is b) list, but the solution provided is d), this d) part is the answer of Q35..similarly in Q37. the answer is a) part, but the solution provided is D), this d) is the answer of previous question..in simple words answer of Q9 was not present but it got shifted to Q10, and answer of Q10 got shifted to Q11...and so on

python revision tour mcq

We are Sorry for your inconvenience . Now we have fixed all problem.

This is a very good program. This has helped me a lot.

Post a Comment

Contact form.

MyCSTutorial- The path to Success in Exam

THE PATH TO SUCCESS IN EXAM...

Python Revision Tour I : Basics of Python – Notes

Class 12 – computer science : python revision tour – i, [a] – basics of python.

Topics are :

  • A : Basics of Pythons
  • B : Decision Making Statements
  • C : Loop and Jump Statements

INTRODUCTION

A python is an object-oriented, interpreted, high-level language and a very powerful programming language.

Developed by Guido Van Rossum  in 1991.

INSTALLATION

Download it from www.python.org  and install your computer by clicking on the installation file.

WORKING IN PYTHON 

In two modes  – (i) Interactive Mode and  (ii) Script Mode.

TOKENS IN PYTHON

The smallest individual unit in a program is called a token.

TYPES OF TOKEN

(i) Keyword  (ii) Identifiers   (iii) Literals  (iv) Operators  & (v) Punctuators

The word has a special meaning in a programming language.  If, else, while, for, or etc 

How to find the list of keywords in Python?

python_keyword_list

Identifiers

Names that are given to different parts of programs. Variable, Function, Class, etc.

Data items that have a fixed value.  Several types of literal in Python.

(a) String  (b) Numeric (c) Boolean (d) None

Triggers some computation or action when applied to the variables. +, -, / .

Punctuators

Symbols that are used  to organize sentence, structures and expressions. ‘  “ #  \ ( ) { } @ , : ; ` =, etc.

STRUCTURE  OF PYTHON PROGRAM

# This is a single line  comment # Function def thanks( name ):   print(“Thanks Mr/Ms. “, name , “for watching Anjeev Singh academy”) #Main Program a  =  20  # variable declaration and intialization b  =  30  c  =  a  +    b  # expression print (“Sum of “, a”, “and”, b, “is”, c )  if c > 40 :  # start of if block , showing by :   print(“You are eligible for lucky draw”) else:   print(“Sorry, Better Luck next time….”)

VARIABLES AND ASSIGNMENTS

A Variable is a named memory location, used for storing and manipulating values.

Example : Name = “Rashmi” , Age   = 18

python revision tour mcq

DYNAMIC TYPING

A variable pointing to a value of a certain type can be made to point to a value/object of a different type. This is called Dynamic Typing. For example:

N = “Rashmi”

N   = 18

python revision tour mcq

MULTIPLE ASSIGNMENTS

Assigning same value to multiple variables. E.g.  a = b = c = 10

Assigning  multiple values to multiple variables. E.g.  a , b , c  = 10, 20, 30

In python 3.x , input( ) is a built-in function, which allows user to input a value.

in_varibale  = input( <prompt message> )

Note : input( ) function always return  a value of String type.

int ( ) :- To convert a value in integer. => x = int (input(“A number plz”)).

float() :- To convert a value in float. => f = float (input(“a number plz:”)).

bool( ) :- To convert a value in Boolean. => b = bool (input(“Boolean value plz:”)) .

PRINT / OUTPUT

In python 3.x, print( ) is a built-in function, which allows the user to send output to a standard output device, i.e. monitor.

print( object , [ sep = ‘ ‘  or <separator string>, end = ‘\n’ or <end-string>] )

print (“Hello”) print (“Your marks is”, 20) print (“Welcome”, “You”, “All”, sep = ‘===‘) print( “Mobile”, end=‘ ‘) print (“9898989898”)

Data types are means to identify the type of data and the set of valid operations for it.

There are the following built-in core data types:-

python revision tour mcq

Numbers Data Types

Integers – Two types of integers in Python

  • a) Integer (signed) – number having only integer, either positive or negative
  • b) Booleans – represent truth values False and True. Boolean values False and True behave like values 0 and 1, respectively.

Floating Point Numbers

Is used to store numbers with a fraction part. They can be represented in scientific notation. Also called real numbers.

Example :  x = 25.036

     y = 4.95e3  => 495.00  => 4.95 x 10^3

Complex Numbers

Python allows to store the complex number.  Complex numbers are pairs of real and imaginary numbers. They can store in the form of ‘a+bj .  Both real and imag are internally represented as float value.

Example :   t = 2 + 3j

    t.real => gives the real part

    t.imag => gives the imaginary part as a float.

Sequence Data Types

Sequence Data Types is an ordered collection of items, indexed by integers (both +ve or –ve). Three types of sequence are – 

The string is a combination of letters, numbers, and special symbols.  In Python 3.x string is a sequence of Pure Unicode characters. Unicode is a system, designed to represent every character from every language.

Example : – “abc”, “12536”, “&*)()^%$”, “abcd12365&^%#’

A string is a sequence of characters and each character can be individually accessed using its index position i.e. forward (0,1, 2, …) and backward (-1, -2, -3, .. …)

The list is a set of comma-separated values of any datatype inside the square brackets. [  ]

Example =>  [1, 2 , 3 , 4, 5]  

    [1.5, 2.5, 4.5, 9.8] 

    [‘x’,  ‘y’, ‘z’]

    [‘anjeev’, 25,  4589.36, True]

The list can also be accessed through the index position i.e. forward and backward.

Related Posts

society law ethics

Society, Law, and Ethics: Societal Impacts – Notes

Interface python with mysql – notes, sql functions , grouping records, joins in sql – notes, simple queries in sql – notes, table creating and data manipulation commands – notes, relational databases – notes, network security aspects – notes, data communication – notes, leave a comment cancel reply.

You must be logged in to post a comment.

You cannot copy content of this page

python revision tour mcq

Free Computer Science Tutorial

Python for class 11 Tutorial, Python for class 12 Tutorial, C language tutorial, SQL Tutorial, Tips & Tricks, sample papers class 12, C++ tutorial

Class 12 Python Revision Tour 2 MCQ | Python Revision Tour 2 Class 12 Quiz

Wrong shortcode initialized

You have successfully subscribed.

There was an error while trying to send your request. Please try again.

Subscribe for Latest Updates

IMAGES

  1. python revision tour class 12 mcq 2021 pdf download

    python revision tour mcq

  2. Python Class 12

    python revision tour mcq

  3. Best 400+ MCQ on Python Revision Tour Class 12

    python revision tour mcq

  4. Python Revision Tour Board MCQ Class 12

    python revision tour mcq

  5. #2 Python Revision Tour

    python revision tour mcq

  6. [Important] Python Revision Tour Class 12 with Solved MCQ

    python revision tour mcq

VIDEO

  1. Python Revision Tour

  2. Python Revision Tour

  3. Python Revision Tour

  4. Day 38: Python Revision Tour 4

  5. Python Revision Tour

  6. Python Revision Tour 1

COMMENTS

  1. 150+ MCQ Revision Tour of python class 12 CBSE Python

    150+ MCQ Revision Tour of python class 12 Unit -1: Computational Thinking and Programming-2 Topic: Revision of python topics covered in class XI. 1. Which of the following is a valid identifier: a) 9type b) _type c) Same-type . d) True. Show Answer

  2. Best 400+ MCQ on Python Revision Tour Class 12

    Python Revision Tour Class 12 Topic Wise MCQ. 1. 140+ MCQ on Introduction to Python. 2. 120 MCQ on String in Python. 3. 100+ MCQ on List in Python. 4. 50+ MCQ on Tuple in Python. 5. 100+ MCQ on Flow of Control in Python. 6. 60+ MCQ on Dictionary in Python.

  3. Class 12 Computer Science MCQs Python Revision Tour Set

    Class 12 Computer Science 083 Python Revision Tour Set 1 Multiple Choice Questions [MCQs] 1. Who is the founder (designed by) of Python? a) Charles Babbage b) Guido Van Rossum c) Guido Gosling d) James Gosling 2. Python development is started in which year? a) 1990 b) 1991 c) 1992 d) 1989 3. Python is […]

  4. python revision tour class 12 mcq 2021 pdf download

    Python revision tour class 12 mcq 2021 pdf download. Core basics. Input and type converion Conditional Statements Function List and for-loops More on for-loops_list_iterables Strings Dictionaries Files. 2.9 Chapter Summary Literals are data that are entered directly into the code. Data has type, for example, int (integer),

  5. Python Revision Tour

    Get answers to all exercises of Chapter 1: Python Revision Tour Sumita Arora Computer Science with Python CBSE Class 12 book. Clear your computer doubts instantly & get more marks in computers exam easily. Master the concepts with our detailed explanations & solutions.

  6. [Important] Python Revision Tour Class 12 with Solved MCQ

    This video is for all class 12 CBSE students, watch the complete python revision tour for class 12.Follow and understand the python concepts with SOLVED impo...

  7. Python Revision Tour Class 12 MCQ

    Python Revision Tour Class 12 MCQ. 20/12/202226/11/2022 by CBSEskilleducation. Teachers and Examiners ( CBSESkillEduction) collaborated to create the Python Revision Tour Class 12 MCQ. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12. Contents show.

  8. Python Revision Tour (LIVE)

    Python Revision Tour (LIVE) | MCQs for Term 1 | Class 12 Computer ScienceMCQs of class 12 computer science, term 1 mcqs for class 12 computer scienceJoin thi...

  9. [IMPORTANT] Python revision tour class 12

    This video is for all class 12 CBSE students, watch the complete python revision tour for class 12.Follow and understand the python concepts with SOLVED impo...

  10. Class 12 Computer Science MCQs Python Revision Tour Set

    Class 12 Computer Science 083 Python Revision Tour Set 2 Multiple Choice Questions (MCQs) 21. Is Python case sensitive when dealing with identifiers? a) Yes b) No c) Machine dependent d) None of these 22. Which of the following is an invalid variable? a) name_of_student b) 2_name_of_student c) student_name_2 d) None of these 23. Which […]

  11. Python Revision Tour 1 Class 12 Questions with Answers

    Special characters (#, @, $,%,!) should be avoided in identifiers. Python Revision Tour 1 Class 12 Questions with Answers. 6. What is Variable? Answer -A variable is a location in memory where a value is stored in a computer language. In Python, a variable is formed when a value is put into it.

  12. Python Revision Tour 1 Class 12 MCQ

    05/11/2022 by CBSEskilleducation. Teachers and Examiners ( CBSESkillEduction) collaborated to create the Python Revision Tour 1 Class 12 MCQ. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12. Contents show.

  13. Python Revision Tour II

    Get answers to all exercises of Chapter 2: Python Revision Tour II Sumita Arora Computer Science with Python CBSE Class 12 book. Clear your computer doubts instantly & get more marks in computers exam easily. Master the concepts with our detailed explanations & solutions.

  14. Python Revision Tour Worksheet Class 12

    in Python for Class 12. Multiple Choice Questions: (20 x 1=20) 1. What will be the output of the following Python code? from math import factorial. print (math.factorial (5)) (a) 120. (b) Nothing is printed. (c) Error, method factorial doesn't exist in math module.

  15. Python Class 12

    Python Class 12 | Chapter 1 | Important MCQ's | Python Revision Tour - 1Telegram Group: https://t.me/codeituplearnersTelegram Channel: https://t.me/i_t_s_a_n...

  16. 2. Python Revision Tour

    Python Revision Tour - I. Python Revision Tour - II. Working with function. Using Python Libraries. Recursion. Data File Handling: Working with Text files. Data File Handling: Working with Binary files. Data File Handling: Working with CSV files. Data Structure: Searching and Sorting.

  17. PDF MCQ CHAPTER

    MCQ CHAPTER - REVISION TOUR CLASS TEST - I Class XII Sub : CS (083) Time: 40 Min Max Marks: 20 1. Which of these in not a core data type? a) Lists b) Dictionary c) Tuples d) Class 2. Given a function that does not return any value, What value is thrown by default when executed in shell. a) int b) bool c) void

  18. Python Revision Tour

    Python Revision Tour - II quiz for 12th grade students. Find other quizzes for Computers and more on Quizizz for free!

  19. Python revision Tour || Multiple Choice Questions || Class 12

    EDIT: I just noticed a pattern, the answers in itself aren't wrong..its just that, the numbering is wrong. For eg- In Q36. the answer is b) list, but the solution provided is d), this d) part is the answer of Q35..similarly in Q37. the answer is a) part, but the solution provided is D), this d) is the answer of previous question..in simple words answer of Q9 was not present but it got shifted ...

  20. Class 12 Python Revision Tour 1 important questions

    This video contains Class 12 Python Revision Tour 1 important MCQ. It also describes Class 12 Python Revision tour important Questions. Answers to these qu...

  21. Python Revision Tour I : Basics of Python

    Class 12 - Computer Science : Python Revision Tour - I [A] - Basics of Python Topics are : INTRODUCTION A python is an object-oriented, interpreted, high-level language and a very powerful programming language. Developed by Guido Van Rossum in 1991. INSTALLATION Download it from www.python.org and install your computer by clicking on the installation […]

  22. Objective Type Questions (Part-1) |Python Revision Tour

    Objective Type Questions (Part-1) |Python Revision Tour | CBSE CLass 12 | Computer Science|Pythonpython class 12 mcq questionsIn this video, I have explained... CBSE Exam, class 12

  23. Class 12 Python Revision Tour 2 MCQ

    Mobile phone tricks.Python tutorial for beginners. python for class xi. python for class xii. python for bca. c language tutorial Class 12 Python Revision Tour 2 MCQ | Python Revision Tour 2 Class 12 Quiz - Free Computer Science Tutorial