Python String Quiz

This quiz focuses on testing and improving your understanding of Python strings, one of the most widely used data types in programming.

Last Updated :
Discuss
Comments

Question 1

What is the output of the following program?

Python
a = 2
b = '3.77'
c = -8
s = '{0:.4f} {0:3d} {2} {1}'.format(a, b, c) 
print(s) 
  • 2.0000 2 -8 3.77

  • 2 3.77 -8 3.77

  • 2.000 3 -8 3.77

  • 2.000 2 8 3.77

Question 2

What are strings in Python?
 

  • Arrays of bytes representing Unicode characters

  • Arrays of integers representing characters

  • Single characters only

  • Arrays of floats representing characters

Question 3

What does the string method .join() do in Python?
 

  • Splits a string into a list

  • Concatenates a list of strings into one string

  • Reverses a string

  • Returns the index of a substring in the string

Question 4

Which method can be used to handle strings with both single and double quotes simultaneously in Python?
 

  • Using triple quotes

  • Using backslash ()

  • Using parentheses

  • Using single quotes only

Question 5

How can you print a string without resolving escape sequences in Python?
 

  • By using the repr() function

  • By using the eval() function

  • By using the str() function

  • By using the format() function

Question 6

What is the primary reason that updating or deleting characters from a string in Python is not allowed?
 

  • Strings are mutable data types

  • Python strings are immutable data types

  • Python doesn't support character-level operations on strings

  • Python string operations are not efficient

Question 7

What is the purpose of the find() function in Python strings?
 

  • It returns the position of the last occurrence of a substring within a string.

  • It returns true if the string begins with a specified prefix.

  • It returns the position of the first occurrence of a substring within a string.

  • It returns true if all the letters in the string are lowercased.

Question 8

What does the startswith() function in Python do?
 

  • It returns true if all the letters in the string are uppercased.

  • It returns true if the string starts with a specified prefix.

  • It returns true if the string ends with a specified suffix.

  • It returns true if all the letters in the string are lowercased

Question 9

What does the title() method do in Python strings?
 

  • It converts the first letter of every word to uppercase and others to lowercase.

  • It swaps the cases of all letters in the string.

  • It converts all letters to uppercase.

  • It converts all letters to lowercase.

Question 10

What is the time complexity of the find() function in Python?
 

  • O(log n)

  • O(n^2)

  • O(n)

  • O(1)

There are 16 questions to complete.

Take a part in the ongoing discussion