Multiple Choice Questions -strings

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Aparnasunil75
A
Aparnasunil75
Community Contributor
Quizzes Created: 20 | Total Attempts: 42,225
| Attempts: 760
SettingsSettings
Please wait...

    1/10 Questions
  • A string is a sequence of characters enclosed in ………

    • Single quote       
    • Triple quote        
    • Double quote
    • All of the above
Please wait...
About This Quiz

This quiz on Multiple Choice Questions - Strings assesses understanding of Python string operations. It covers basic operations, slicing, concatenation, and common methods, evaluating practical knowledge essential for programming in Python.

Multiple Choice Questions -strings - Quiz

Questions and Answers
  • 2. 

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

    • A

    • Bc

    • Bca

    • Abc

    Correct Answer
    A. 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

    • Ab

    • Cd

    • Dc

    Correct Answer
    A. 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

    • +

    • *

    • -

    • All of the above

    Correct Answer
    A. -
    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]

    • Dlrowolleh

    • Hello

    • World

    • 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’)?

    • 2

    • 1

    • None

    • 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”)

    • Dlrowolleh

    • True

    • -1

    • None

    Correct Answer
    A. 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")

    • Error

    • -1

    • 1

    • 0

    Correct Answer
    A. 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")

    • -1

    • 4

    • 3

    • 1

    Correct Answer
    A. 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 ___________

    • Error

    • Int

    • Bool

    • Str

    Correct Answer
    A. 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 (Updated): Mar 21, 2023 +

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.