Multiple Choice Questions -strings

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Aparnasunil75
A
Aparnasunil75
Community Contributor
Quizzes Created: 20 | Total Attempts: 35,335
Questions: 10 | Attempts: 736

SettingsSettingsSettings
Multiple Choice Questions -strings - Quiz

.


Questions and Answers
  • 1. 

    A string is a sequence of characters enclosed in ………

    • A.

      Single quote       

    • B.

      Triple quote        

    • C.

      Double quote

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    A string is a sequence of characters enclosed in either single quotes, triple quotes, or double quotes. Single quotes are used to represent a string that contains only one character, while double quotes are used for strings that contain more than one character. Triple quotes are used for multiline strings or strings that span multiple lines. Therefore, all of the options mentioned (single quote, triple quote, and double quote) can be used to enclose a string.

    Rate this question:

  • 2. 

    What will be the output of the following Python statement?    >>>”a”+“bc”

    • A.

      A

    • B.

      Bc

    • C.

      Bca

    • D.

      Abc

    Correct Answer
    D. Abc
    Explanation
    The given Python statement is concatenating two strings: "a" and "bc". The output of this statement will be the string "abc".

    Rate this question:

  • 3. 

    What will be the output of the following Python statement?    >>>”abcd”[2:]

    • A.

      A

    • B.

      Ab

    • C.

      Cd

    • D.

      Dc

    Correct Answer
    C. Cd
    Explanation
    The given Python statement is slicing the string "abcd" starting from index 2 till the end of the string. Therefore, the output will be "cd".

    Rate this question:

  • 4. 

    What arithmetic operators cannot be used with strings

    • A.

      +

    • B.

      *

    • C.

      -

    • D.

      All of the above

    Correct Answer
    C. -
    Explanation
    The operator "-" cannot be used with strings. This is because the "-" operator is used for subtraction in arithmetic operations, and it does not have any meaning when applied to strings. Strings are sequences of characters, and subtraction is not a meaningful operation for them. Therefore, the "-" operator cannot be used with strings.

    Rate this question:

  • 5. 

    What will be the output of the following Python code? >>>str1="helloworld" >>>str1[::-1]

    • A.

      Dlrowolleh

    • B.

      Hello

    • C.

      World

    • D.

      Helloworld

    Correct Answer
    A. Dlrowolleh
    Explanation
    The given code reverses the string "helloworld" using slicing syntax [::-1]. This means it starts from the last character and goes backwards, resulting in the output "dlrowolleh".

    Rate this question:

  • 6. 

    Given a string example=”hello” what is the output of example.count(‘l’)?

    • A.

      2

    • B.

      1

    • C.

      None

    • D.

      0

    Correct Answer
    A. 2
    Explanation
    The output of example.count('l') is 2 because the count() method in Python returns the number of occurrences of a specified value in a string. In this case, 'l' appears twice in the string "hello", so the count is 2.

    Rate this question:

  • 7. 

    ) What will be the output of the following Python code? 1. >>>example=”helloworld” 2.>>>example[::1].startswith(“d”)

    • A.

      Dlrowolleh

    • B.

      True

    • C.

      -1

    • D.

      None

    Correct Answer
    B. True
    Explanation
    The given Python code first assigns the string "helloworld" to the variable "example". Then, it uses slicing with a step of 1 (i.e., [::1]) to reverse the string. The reversed string is "dlrowolleh". Finally, the code checks if the reversed string starts with the letter "d". Since it does, the output will be "true".

    Rate this question:

  • 8. 

    What will be the output of the following Python code? >>>example = "helle" >>>example.find("e")

    • A.

      Error

    • B.

      -1

    • C.

      1

    • D.

      0

    Correct Answer
    C. 1
    Explanation
    The output of the code will be 1. The find() function in Python returns the index of the first occurrence of the specified substring within the string. In this case, the substring "e" is found at index 1 in the string "helle".

    Rate this question:

  • 9. 

    What will be the output of the following Python code? >>>example = "helle" >>>example.rfind("e")

    • A.

      -1

    • B.

      4

    • C.

      3

    • D.

      1

    Correct Answer
    B. 4
    Explanation
    The output of the code will be 4. The rfind() function in Python returns the highest index of the substring "e" in the string "helle". Since "e" appears at index 1 and index 4 in the string, the highest index is 4.

    Rate this question:

  • 10. 

    The format function, when applied on a string returns ___________

    • A.

      Error

    • B.

      Int

    • C.

      Bool

    • D.

      Str

    Correct Answer
    D. Str
    Explanation
    The format function, when applied on a string, returns a formatted string. It allows for the insertion of values into specific positions within the string by using placeholders and arguments. The function converts the arguments into strings and replaces the placeholders in the original string with the corresponding values. Therefore, the correct answer is "str" as the format function returns a string.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 16, 2020
    Quiz Created by
    Aparnasunil75
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.