Python Tuple ,sets and strings

Python Tuple ,sets and strings Quiz

Last Updated :
Discuss
Comments

Question 1

How to create an empty tuple in Python?

  • tup= ()

  • tup= tuple()

  • tup= []

  • Both A and B

Question 2

How can you access the second element of the tuple t = (1, 2, 3)?

  • t[1]

  • t[2]

  • t.get(1)

  • t(1)

Question 3

Which of the following is true for the tuple t = (1, 2, [3, 4])?

  • Tuples cannot contain mutable objects like lists.

  • t[2][0] = 5 is a valid operation.

  • Tuples can be resized.

  • Tuples can only contain integers.

Question 4

Which of the following methods is not available for tuples?

  • .count()

  • .index()

  • .sort()

  • .reverse()

Question 5

Which of the following operations will result in an error when performed on a set?

  • Adding an element

  • Removing an element

  • Accessing an element by index

  • Checking if an element exists

Question 6

What does the following code print?

Python
s = {1, 2, 3}
s.update([4, 5])
print(s)


  • {1, 2, 3}

  • {1, 2, 3, 4, 5}

  • [1, 2, 3, 4, 5]

  • Error

Question 7

What will be the output of the following code?

Python
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1 & set2)


  • {1, 2, 3, 4, 5}

  • {3}

  • {1, 2, 4, 5}

  • Error

Question 8

What is the difference between remove and discard methods in a set?

  • remove adds an element, discard removes an element

  • remove raises an error if the element is not found, discard does not

  • remove removes all elements, discard removes the first element

  • remove raises an error if the element is not found, discard adds an element

Question 9

Which method is used to check if a string contains only digits?

  • str.isdigit()

  • str.checkDigits()

  • str.onlyDigits()

  • str.isnumeric()

Question 10

What does the len() function return when applied to a string in Python?

  • The number of words in the string

  • The length of the string in characters

  • The number of characters in the string excluding spaces

  • The total number of spaces in the string

Tags:

There are 13 questions to complete.

Take a part in the ongoing discussion