Which of the following statement will reverse the list l1 MCQ

Q1. Which of the following statement will create list?

a. L1=list( )

b. L1=[1,2,3,4]

c. Both of the above

d. None of the above

Ans. c. Both of the above

70+ List in Python MCQ Class 11-12

21. What will be the output of the following code segment?

list1 =[‘Red’, ‘Green’, ‘Blue’, ‘Cyan’, ‘Magenta’,

‘Yellow’, ‘Black’]

print(list1[-4:0:-1])

a) [‘Cyan’, ‘Blue’, ‘Green’, ‘Red’]

b) []

c) [‘Cyan’, ‘Blue’, ‘Green’]

d) [‘Cyan’, ‘Magenta’, ‘Yellow’, ‘Black’]

Show Answer

c) [‘Cyan’, ‘Blue’, ‘Green’]

22. Which of the following is a mutable sequence data type?

a) string

b) list

c) tuple

d) All of the mentioned

Show Answer

b) list

23. Which of the following is not an immutable data type:

a) string

b) complex

c) list

d) tuple

Show Answer

c) list

24. Which statement does not show any error after execution? Given L=[1,2,3,4] (U)

a) print(L+L)

b) print(L*L)

c) print(L-L)

d) All of the mentioned

Show Answer

a) print(L+L)

25. Which of the following command(s) will create a list?

a) list1 = list()

b) list1 = []

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

d) all of these

Show Answer

d) all of these

26. Which command can we use to insert 5 to the third position in list1?

a) list1.insert(3, 5)

b) list1.insert(2, 5)

c) list1.add(3, 5)

d) list1.append(3, 5)

Show Answer

b) list1.insert(2, 5)

27. Which of the following commands will sort list1 in descending order?

a) list1.sort(reverse=0)

b) list1.sort()

c) list1.sort(reverse=‘True’)

d) list1.sort(reverse=1)

Show Answer

d) list1.sort(reverse=1)

28. Which command we use cane use To remove string “hello” from list1, Given, list1=[“hello”]

a) list1.remove(“hello”)

b) list1.pop(list1.index(‘hello’))

c) both a & b

d) none of these

Show Answer

c) both a & b

29. What will be the output of the following code segment?

list1 = [10,20,30,10,40,10]

print(list1.remove(10))

a) 10

b) [20,30,40]

c) None

d) []

Show Answer

c) None

30. What will be the output of the following code segment?

L=’good’

L=[1,2,3]

n=2

print(L*n)

a) goodgood

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

c) error

d) none

Show Answer

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

31. What will be the output of the following code segment?

l=[‘A’,’a’,’Aa’,’aA’]

print(max(l))

a) ‘aA’

b) ‘A’,

c) ‘a’

d) ‘Aa’

Show Answer

a) ‘aA’

32. pop() returns the element whose index is passed as argument to this function and also removes it from the list. If no argument is given,then it returns and removes the _____element ofthe list. Fill in the Blank Space.

a) None

b) first

c) last

d) all

Show Answer

c) last

33. What will be the output of the following code segment?

l=list(range(100,20,-20))

print(l)

a) [100 80 60 40]

b) [100, 80, 60, 40]

c) [100,20,-20]

d) error

Show Answer

b) [100, 80, 60, 40]

34. What will be the output of the following code segment?

myList = [1,2,3,4,5,6,7,8,9,10]

newList=[]

for i in range(0,len(myList)):

if i%2 == 0:

newList.append(myList[i])

print(newList)

a) [1,3,5,7,9]

b) [1,3,5,7]

c) []

d) [1,2,3,4,5,6,7,8,9,10]

Show Answer

a) [1,3,5,7,9]

35. Given list1 = [34,66,12,89,28,99]

Statement 1: list1.reverse()

Statement 2: list1[::-1]

Which statement modifies the contents of original list1.

a) Statement 1

b) Statement 2

c) Both Statement 1 and 2.

d) none of the mentioned

Show Answer

a) Statement 1

36. Given a string: s=”String”. Which statement converts string ‘s’ into List ‘L’.

a) L=s

b) L=list(s)

c) L=s[::]

d) all of the mentioned

Show Answer

b) L=list(s)

37. What will be the output of the following code segment?

list1 = [10,20,30,10,40,10]

print(list1.index(10))

a) [0]

b) [0,3,5]

c) 0

d) 1 3 5

Show Answer

c) 0

38. The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) isstored in the following list:

stRecord = [‘Raman’,’A-36′,[56,98,99,72,69], 78.8]

Write Python statements to retrieve the following information from the list stRecord.

a) print(stRecord [2][4])

b) print(stRecord [2][-1])

c) print(stRecord [-2][-1])

d) all of the mentioned

Show Answer

d) all of the mentioned

39. S1: Operator + concatenates one list to the end of another list.

S2: Operator * is to multiply the elements inside the list.

Which option is correct?

a) S1 is correct, S2 is incorrect

b) S1 is incorrect, S2 is incorrect

c) S1 is incorrect, S2 is incorrect

d) S1 is incorrect, S2 is correct

Show Answer

a) S1 is correct, S2 is incorrect

40. Which type of copy is shown in the following python code?

1s1=[[10, 20], [30, 40], [50, 60]]

1s2=list(1s1)

a) Shallow copy

b) Deep copy

c) memberwise

d) All of the mentioned

Show Answer

a) Shallow copy

70+ List in Python MCQ Class 11-12

41. What is the data type of x after the following statement?

x = [7, 8, 9, 10]

a) List

b) Dictionary

c) Tuple

d) String

Show Answer

a) List

42. What is the data type of x after the following statement?

x = [‘Today’, ‘Tomorrow’, ‘Yesterday’]

a) List

b) Dictionary

c) Tuple

d) String

Show Answer

a) List

43. What will be the output after the following statements?

x = [‘Today’, ‘Tomorrow’, ‘Yesterday’]

y = x[1]

print(y)

a) x1

b) Today

c) Tomorrow

d) Yesterday

Show Answer

c) Tomorrow

44. What will be the output after the following statements?

x = [25, 35, 45]

y = x[0]

print(y)

a) x0

b) 25

c) 35

d) 45

Show Answer

b) 25

45. What will be the output after the following statements?

x = [10, 20, 30]

y = x[1] + x[2]

print(y)

a) 20

b) 30

c) 40

d) 50

Show Answer

d) 50

46. What will be the output after the following statements?

x = [‘Sunday’, ‘Monday’, ‘Tuesday’]

y = x[1] + x[2]

print(y)

a) MondayTuesday

b) SundayMonday

c) SunMonday

d) Monday Tuesday

Show Answer

a) MondayTuesday

47. What will be the output after the following statements?

x = [[0.0, 1.0, 2.0],[4.0, 5.0, 6.0]]

y = x[1][2]

print(y)

a) 0.0

b) 1.0

c) 5.0

d) 6.0

Show Answer

d) 6.0

48. What will be the output after the following statements?

x = [[0.0, 1.0, 2.0],[4.0, 5.0, 6.0]]

y = x[0][1] + x[1][0]

print(y)

a) 1.0

b) 4.0

c) 5.0

d) 6.0

Show Answer

c) 5.0

49. What will be the output after the following statements?

x = 3

y = 4

print(x*y)

a) 3

b) 4

c) 3 4

d) 12

Show Answer

d) 12

50. What will be the output after the following statements?

x = [15, 45, 85, 95]

print(x[3]-x[1])

a) 30

b) 40

c) 50

d) 10

Show Answer

c) 50

51. What will be the output after the following statements?

x = [5, 4, 3, 2]

print(x)

a) [5, 4, 3, 2]

b) 5, 4, 3, 2

c) 5432

d) (5, 4, 3, 2)

Show Answer

a) [5, 4, 3, 2]

52. What will be the output after the following statements?

x = [5, 4, 3, 2]

x.append(1)

print(x)

a) [5, 4, 3, 2]

b) 5, 4, 3, 2, 1

c) 5432

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

Show Answer

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

53. What will be the output after the following statements?

x = [5, 4, 3, 2]

x.insert(1, 0)

print(x)

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

b) [5, 0, 4, 3, 2]

c) [0, 5, 4, 3, 2]

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

Show Answer

b) [5, 0, 4, 3, 2]

54. What will be the output after the following statements?

x = [5, 4, 3, 2]

x.remove(2)

print(x)

a) [5, 3, 2]

b) [5, 4, 3]

c) [5, 4, 2]

d) [3, 2]

Show Answer

b) [5, 4, 3]

55. What will be the output after the following statements?

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

print(x.pop(3))

a) 4

b) 3

c) 2

d) 1

Show Answer

c) 2

56. What will be the output after the following statements?

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

print(x.index(1))

a) 4

b) 3

c) 2

d) 1

Show Answer

a) 4

57. What will be the output after the following statements?

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

x.extend(x)

print(x)

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

b) []

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

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

Show Answer

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

58. What will be the output after the following statements?

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

y = [0, 5, 10]

x.extend(y)

print(x)

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

b) []

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

d) [0, 5, 10, 5, 4, 3, 2, 1]

Show Answer

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

59. What will be the output after the following statements?

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

y = [10, 5, 0]

x.extend(y)

print(y)

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

b) []

c) [10, 5, 0, 5, 4, 3, 2, 1]

d) [10, 5, 0]

Show Answer

d) [10, 5, 0]

60. What will be the output after the following statements?

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

y = [10, 5, 0]

y.extend(x)

print(y)

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

b) [10, 5, 0, 5, 4, 3, 2, 1]

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

d) [10, 5, 0]

Show Answer

b) [10, 5, 0, 5, 4, 3, 2, 1]

Python List MCQs

This section focuses on the "list" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1.Which of the following would give an error?

A. list1=[]
B. list1=[]*3
C. list1=[2,8,7]
D. None of the above

View Answer

Ans : D

Explanation: None of the above will result in error.


2.Which of the following is True regarding lists in Python?

A. Lists are immutable.
B. Size of the lists must be specified before its initialization
C. Elements of lists are stored in contagious memory location.
D. size(list1) command is used to find the size of lists.

View Answer

Ans : C

Explanation: Elements of lists are stored in contagious memory location is True regarding lists in Python.


3.What will be the output of below Python code?

list1=[8,0,9,5]
print(list1[::-1])

A. [5,9,0,8]
B. [8,0,9]
C. [8,0,9,5]
D. [0,9,5]

View Answer

Ans : A

Explanation: [5,9,0,8] will be the output of below Python code.


4.Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

A. print(list1[1:7:2])
B. print(list1[0:7:2])
C. print(list1[1:8:2])
D. print(list1[0:8:2])

View Answer

Ans : C

Explanation: print(list1[1:8:2]) of the following will give output as [23,2,9,75].


5.The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student’s average mark be calculated?

A. print(avg(list1))
B. print(sum(list1)/len(list1))
C. print(sum(list1)/sizeof(list1))
D. print(total(list1)/len(list1))

View Answer

Ans : B

Explanation: the student’s average mark be calculated through print(sum(list1)/len(list1)).


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

list1=["Python","Java","c","C","C++"]
print(min(list1))

A. c
B. C++
C. C
D. min function cannot be used on string elements

View Answer

Ans : C

Explanation: C will be the output of following Python code.


7.The elements of a list are arranged in descending order. Which of the following two will give same outputs?
i. print(list_name.sort())
ii. print(max(list_name))
iii. print(list_name.reverse())
iv. print(list_name[-1])

A. i, ii
B. i, iii
C. ii, iii
D. iii, iv

View Answer

Ans : B

Explanation: print(list_name.sort()) and print(list_name.reverse()) will give same outputs.


8. What will be the result after the execution of above Python code?

list1=[3,2,5,7,3,6]
list1.pop(3)
print(list1)

A. [3,2,5,3,6]
B. [2,5,7,3,6]
C. [2,5,7,6]
D. [3,2,5,7,3,6]

View Answer

Ans : A

Explanation: [3,2,5,3,6] will be the result after the execution of above Python code.


9.What will be the output of below Python code?

list1=[1,3,5,2,4,6,2]
list1.remove(2)
print(sum(list1))

A. 18
B. 19
C. 21
D. 22

View Answer

Ans : C

Explanation: 21 will be the result after the execution of above Python code.


10.What will be the output of below Python code?

list1=["tom","mary","simon"]
list1.insert(5,8)
print(list1)

A. ["tom", "mary", "simon", 5]
B. ["tom", "mary", "simon", 8]
C. [8, "tom", "mary", "simon"]
D. Error

View Answer

Ans : B

Explanation: ["tom", "mary", "simon", 8] will be the result after the execution of above Python code.





Discussion


* You must be logged in to add comment.

vanur swamy
it is very easy to understand

Python MCQ (Multi Choice Questions)

1) What is the maximum possible length of an identifier?

  1. 16
  2. 32
  3. 64
  4. None of these above
Show Answer Workspace

Answer: (d) None of these above

Explanation: The maximum possible length of an identifier is not defined in the python language. It can be of any number.

2) Who developed the Python language?

  1. Zim Den
  2. Guido van Rossum
  3. Niene Stom
  4. Wick van Rossum
Show Answer Workspace

Answer: (b) Guido van Rossum

Explanation: Python language was developed by Guido van Rossum in the Netherlands.

3) In which year was the Python language developed?

  1. 1995
  2. 1972
  3. 1981
  4. 1989
Show Answer Workspace

Answer: (d) 1989

Explanation: Python language was developed by Guido van Rossum in 1989.

4) In which language is Python written?

  1. English
  2. PHP
  3. C
  4. All of the above
Show Answer Workspace

Answer: (b) C

Explanation: Python is written in C programming language, and it is also called CPython.

5) Which one of the following is the correct extension of the Python file?

  1. .py
  2. .python
  3. .p
  4. None of these
Show Answer Workspace

Answer: (a) .py

Explanation: ".py" is the correct extension of the Python file.

6) In which year was the Python 3.0 version developed?

  1. 2008
  2. 2000
  3. 2010
  4. 2005
Show Answer Workspace

Answer: (a) 2008

Explanation: Python 3.0 version was developed on December 3, 2008.

7) What do we use to define a block of code in Python language?

  1. Key
  2. Brackets
  3. Indentation
  4. None of these
Show Answer Workspace

Answer: (c) Indentation

Explanation: Python uses indentation to define blocks of code. Indentations are simply spaces or tabs used as an indicator that is part of the indent code child. As used in curly braces C, C++, and Java.

8) Which character is used in Python to make a single line comment?

  1. /
  2. //
  3. #
  4. !
Show Answer Workspace

Answer: (c) #

Explanation: "#" character is used in Python to make a single-line comment.

9) Which of the following statements is correct regarding the object-oriented programming concept in Python?

  1. Classes are real-world entities while objects are not real
  2. Objects are real-world entities while classes are not real
  3. Both objects and classes are real-world entities
  4. All of the above
Show Answer Workspace

Answer: (b) Objects are real-world entities while classes are not real

Explanation: None

10) Which of the following statements is correct in this python code?

  1. It will throw the error as multiple references to the same object is not possible
  2. id(name1) and id(name2) will have same value
  3. Both name1 and name2 will have reference to two different objects of class Name
  4. All of the above
Show Answer Workspace

Answer: (b) id(name1) and id(name2) will have same value

Explanation: "name1" and "name2" refer to the same object, so id(name1) and id(name2) will have the same value.

11) What is the method inside the class in python language?

  1. Object
  2. Function
  3. Attribute
  4. Argument
Show Answer Workspace

Answer: (b) Function

Explanation: Function is also known as the method.

12) Which of the following declarations is incorrect?

  1. _x = 2
  2. __x = 3
  3. __xyz__ = 5
  4. None of these
Show Answer Workspace

Answer: (d) None of these

Explanation: All declarations will execute successfully but at the expense of low readability.

13) Why does the name of local variables start with an underscore discouraged?

  1. To identify the variable
  2. It confuses the interpreter
  3. It indicates a private variable of a class
  4. None of these
Show Answer Workspace

Answer: (c) It indicates a private variable of a class

Explanation: Since there is no concept of private variables in Python language, the major underscore is used to denote variables that cannot be accessed from outside the class.

14) Which of the following is not a keyword in Python language?

  1. val
  2. raise
  3. try
  4. with
Show Answer Workspace

Answer: (a) val

Explanation: "val" is not a keyword in python language.

15) Which of the following statements is correct for variable names in Python language?

  1. All variable names must begin with an underscore.
  2. Unlimited length
  3. The variable name length is a maximum of 2.
  4. All of the above
Show Answer Workspace

Answer: (b) Unlimited length

Explanation: None

16) Which of the following declarations is incorrect in python language?

  1. xyzp = 5,000,000
  2. x y z p = 5000 6000 7000 8000
  3. x,y,z,p = 5000, 6000, 7000, 8000
  4. x_y_z_p = 5,000,000
Show Answer Workspace

Answer: (b) x y z p = 5000 6000 7000 8000

Explanation: Spaces are not allowed in variable names.

17) Which of the following words cannot be a variable in python language?

  1. _val
  2. val
  3. try
  4. _try_
Show Answer Workspace

Answer: (c) try

Explanation: "try" is a keyword.

18) Which of the following operators is the correct option for power(ab)?

  1. a ^ b
  2. a**b
  3. a ^ ^ b
  4. a ^ * b
Show Answer Workspace

Answer: (b) a**b

Explanation: The power operator in python is a**b, i.e., 2**3=8.

19) Which of the following precedence order is correct in Python?

  1. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
  2. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential
  3. Division, Multiplication, Addition, Subtraction, Parentheses, Exponential
  4. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
Show Answer Workspace

Answer: (a) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

Explanation: PEMDAS (similar to BODMAS).

20) Which one of the following has the same precedence level?

  1. Division, Power, Multiplication, Addition and Subtraction
  2. Division and Multiplication
  3. Subtraction and Division
  4. Power and Division
Show Answer Workspace

Answer: (b) Division and Multiplication

Explanation: None

21) Which one of the following has the highest precedence in the expression?

  1. Division
  2. Subtraction
  3. Power
  4. Parentheses
Show Answer Workspace

Answer: (d) Parentheses

Explanation: PEMDAS (similar to BODMAS).

22) Which of the following functions is a built-in function in python language?

  1. val()
  2. print()
  3. print()
  4. None of these
Show Answer Workspace

Answer: (b) print()

Explanation: The print() function is a built-in function in python language that prints a value directly to the system.

23) Study the following function:

What will be the output of this function?

  1. 4
  2. 5
  3. 576
  4. 5
Show Answer Workspace

Answer: (d) 5

Explanation: The round function is a built-in function in the Python language that round-off the value (like 3.85 is 4), so the output of this function will be 5.

24) Which of the following is correctly evaluated for this function?

  1. (x**y) / z
  2. (x / y) * z
  3. (x**y) % z
  4. (x / y) / z
Show Answer Workspace

Answer: (c) (x**y) % z

Explanation: None

25) Study the following function:

What will be the output of this function?

  1. False
  2. True
  3. 0
  4. Invalid code
Show Answer Workspace

Answer: (a) False

Explanation: If any element is zero, it returns a false value, and if all elements are non-zero, it returns a true value. Hence, the output of this "all([2,4,0,6])" function will be false.

26) Study the following program:

What will be the output of this code?

  1. error
  2. 2 1
  3. 0 3 1
  4. None of these
Show Answer Workspace

Answer: (a) error

Explanation: Syntax error, there should not be a space between + and =.

27) Which one of the following syntaxes is the correct syntax to read from a simple text file stored in ''d:\java.txt''?

  1. Infile = open(''d:\\java.txt'', ''r'')
  2. Infile = open(file=''d:\\\java.txt'', ''r'')
  3. Infile = open(''d:\java.txt'',''r'')
  4. Infile = open.file(''d:\\java.txt'',''r'')
Show Answer Workspace

Answer: (a) Infile = open(''c:\\scores.txt'', ''r'')

Explanation: None

28) Study the following code:

What will be the output of this program?

  1. ['XX', 'YY']
  2. ['xx', 'yy']
  3. [XX, yy]
  4. None of these
Show Answer Workspace

Answer: (a) ['XX', 'YY']

Explanation: None

29) Study the following function:

What will be the output of this code?

  1. Error
  2. -6
  3. 6
  4. 6.0
Show Answer Workspace

Answer: (d) 6.0

Explanation: This function prints the square of the value.

30) Study the following function:

What will be the output of this code?

  1. False
  2. Ture
  3. Invalid code
  4. None of these
Show Answer Workspace

Answer: (b) True

Explanation: None

31) Study the following statement:

What will be the output of this statement?

  1. a+bc
  2. abc
  3. a bc
  4. a
Show Answer Workspace

Answer: (b) abc

Explanation: In Python, the "+" operator acts as a concatenation operator between two strings.

32) Study the following code:

What will be the output of this code?

  1. javatpoint
  2. java
  3. point
  4. None of these
Show Answer Workspace

Answer: (c) point

Explanation: Slice operation is performed on the string.

33) The output to execute string.ascii_letters can also be obtained from:?

  1. character
  2. ascii_lowercase_string.digits
  3. lowercase_string.upercase
  4. ascii_lowercase+string.ascii_upercase
Show Answer Workspace

Answer: (d) string.ascii_lowercase+string.ascii_upercase

Explanation: None

34) Study the following statements:

What will be the output of this statement?

  1. t
  2. j
  3. point
  4. java
Show Answer Workspace

Answer: (a) t

Explanation: The correct output of this program is "t" because -1 corresponds to the last index.

35) Study the following code:

What will be the output of this statement?

  1. java
    point
  2. java point
  3. \njavat\npoint
  4. Print the letter r and then javat and then point
Show Answer Workspace

Answer: (c) \njavat\npoint

Explanation: None

36) Study the following statements:

What will be the output of this statement?

  1. 33
  2. 63
  3. 0xA + 0xB + 0xC
  4. None of these
Show Answer Workspace

Answer: (a) 33

Explanation: A, B and C are hexadecimal integers with values 10, 11 and 12 respectively, so the sum of A, B and C is 33.

37) Study the following program:

Which of the following is the correct output of this program?

  1. 32
  2. 32 32
  3. 32 None
  4. Error is generated
Show Answer Workspace

Answer: (d) Error is generated

Explanation: Error is generated because self.o1 was never created.

38) Study the following program:

What will be the output of this statement?

  1. Ann Bob
  2. Ann Nick
  3. Wick Bob
  4. Wick Nick
Show Answer Workspace

Answer: (d) Wick Nick

Explanation: None

39) Study the following statements:

What will be the output of this statement?

  1. 18
  2. -18
  3. 17
  4. -17
Show Answer Workspace

Answer: (b) -18

Explanation: ASCII value of h is less than the z. Hence the output of this code is 104-122, which is equal to -18.

40) Study the following program:

Which of the following is correct output of this program?

  1. ['xy', 'yz']
  2. ['XY', 'YZ']
  3. [None, None]
  4. None of these
Show Answer Workspace

Answer: (a) ['xy', 'yz']

Explanation: None

41) Study the following program:

Which of the following is the correct output of this program?

  1. 1 2 3
  2. 3 2 1
  3. 1 2
  4. Invalid syntax
Show Answer Workspace

Answer: (d) Invalid syntax

Explanation: Invalid syntax, because this declaration (i = 1:) is wrong.

42) Study the following program:

Which of the following is correct output of this program?

  1. 1 2 3 4 5
  2. 1 2 3 4 5 6
  3. 1 2 3 4 5 6 7
  4. Invalid syntax
Show Answer Workspace

Answer: (b) 1 2 3 4 5 6

Explanation: None

43) Study the following program:

What will be the output of this statement?

  1. 1 2 3
  2. 0 1 2 3
  3. 0 1 2
  4. 3 2 1
Show Answer Workspace

Answer: (c) 0 1 2

Explanation: None

44) Study the following program:

What will be the output of this statement?

  1. 0 1
  2. 0 1 2
  3. 0 1 2 0
  4. 0 1 2 3
Show Answer Workspace

Answer: (c) 0 1 2 0

Explanation: None

45) Study the following program:

What will be the output of this statement?

  1. xyz
  2. No output
  3. x y z
  4. j j j j j j j..
Show Answer Workspace

Answer: (b) No output

Explanation: "j" is not in "xyz".

46) Study the following program:

Which of the following is the correct output of this program?

  1. PQRS
  2. pqrs
  3. qrs
  4. None of these
Show Answer Workspace

Answer: (b) pqrs

Explanation: None

47) Study the following program:

What will be the output of this statement?

  1. a b c
  2. 0 1 2
  3. 0 a 1 b 2 c
  4. None of these above
Show Answer Workspace

Answer: (b) 0 1 2

Explanation: None

48) Study the following program:

What will be the output of this statement?

  1. {0, 1, 2} {0, 1, 2} {0, 1, 2}
  2. 0 1 2
  3. Syntax_Error
  4. None of these above
Show Answer Workspace

Answer: (b) 0 1 2

Explanation: None

49) Which of the following option is not a core data type in the python language?

  1. Dictionary
  2. Lists
  3. Class
  4. All of the above
Show Answer Workspace

Answer: (c) Class

Explanation: Class is not a core data type because it is a user-defined data type.

50) What error will occur when you execute the following code?

  1. NameError
  2. SyntaxError
  3. TypeError
  4. ValueError
Show Answer Workspace

Answer: (a) NamaError

Explanation: Mango is not defined hence the name error.

51) Study the following program:

What will be the output of this statement?

  1. hello2hello2
  2. hello2
  3. Cannot perform mathematical operation on strings
  4. indentationError
Show Answer Workspace

Answer: (d) indentationError

Explanation: None

52) Which of the following data types is shown below?

What will be the output of this statement?

  1. Dictionary
  2. Tuple
  3. List
  4. Stack
Show Answer Workspace

Answer: (c) List

Explanation: Any value can be stored in the list data type.

53) What happens when '2' == 2 is executed?

  1. False
  2. Ture
  3. ValueError occurs
  4. TypeError occurs
Show Answer Workspace

Answer: (a) False

Explanation: It only evaluates to false.

54) Study the following program:

What will be the output of this statement?

  1. invalid code
  2. JavaTpoint has not exist
  3. JavaTpoint has exist
  4. none of these above
Show Answer Workspace

Answer: (a) invalid code

Explanation: A new exception class must inherit from a BaseException, and there is no such inheritance here.

55) Study the following statement

Which of the following is the correct statement?

  1. x dictionary z is created
  2. x and y are the keys of dictionary z
  3. 0 and 1 are the values of dictionary z
  4. All of the above
Show Answer Workspace

Answer: (d) All of the above

Explanation: All of the above statements is correct regarding Python code.

Next TopicPython MCQ Part 2


← prev next →


Reversing a List in Python

Python provides us with various ways of reversing a list. We will go through few of the many techniques on how a list in python can be reversed.
Examples:

Input : list = [10, 11, 12, 13, 14, 15] Output : [15, 14, 13, 12, 11, 10] Input : list = [4, 5, 6, 7, 8, 9] Output : [9, 8, 7, 6, 5, 4]

Python List reverse()

Python List reverse() is an inbuilt method in the Python programming language that reverses objects of the List in place.

Syntax:

list_name.reverse()

Parameters:

There are no parameters.



Returns:

The reverse() method does not return any value but reverses the given object from the list.

Error:

When anything other than list is used in place of list, then it returns an AttributeError

Example 1: Reverse a List

Python3




# Python3 program to demonstrate the
# use of reverse method
# a list of numbers
list1 = [1, 2, 3, 4, 1, 2, 6]
list1.reverse()
print(list1)
# a list of characters
list2 = ['a', 'b', 'c', 'd', 'a', 'a']
list2.reverse()
print(list2)

Output:

[6, 2, 1, 4, 3, 2, 1] ['a', 'a', 'd', 'c', 'b', 'a']

Example 2: Demonstrate the Error in reverse() Method

Python3




# Python3 program to demonstrate the
# error in reverse() method
# error when string is used in place of list
string = "abgedge"
string.reverse()
print(string)

Output:

Traceback (most recent call last): File "/home/b3cf360e62d8812babb5549c3a4d3d30.py", line 5, in string.reverse() AttributeError: 'str' object has no attribute 'reverse'

Example 3: Practical Application

Given a list of numbers, check if the list is a palindrome.

Note: Palindrome-sequence that reads the same backward as forwards.

Python3




# Python3 program for the
# practical application of reverse()
list1 = [1, 2, 3, 2, 1]
# store a copy of list
list2 = list1.copy()
# reverse the list
list2.reverse()
# compare reversed and original list
if list1 == list2:
print("Palindrome")
else:
print("Not Palindrome")

Output:

Palindrome




Article Tags :
Python
python-list
python-list-functions
Reverse
Practice Tags :
python-list
Reverse
Read Full Article

Video liên quan

Postingan terbaru

LIHAT SEMUA