Software Development Exam  >  Software Development Tests  >  Basics of Python  >  Test: Strings - 2 - Software Development MCQ

Test: Strings - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test Basics of Python - Test: Strings - 2

Test: Strings - 2 for Software Development 2024 is part of Basics of Python preparation. The Test: Strings - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Strings - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Strings - 2 below.
Solutions of Test: Strings - 2 questions in English are available as part of our Basics of Python for Software Development & Test: Strings - 2 solutions in Hindi for Basics of Python course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Strings - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study Basics of Python for Software Development Exam | Download free PDF with solutions
1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Strings - 2 - Question 1

Which of the following statements about strings in Python is correct?

Detailed Solution for Test: Strings - 2 - Question 1

Strings can be defined using single quotes ('') or double quotes (""). For example: 'Hello' and "World" are both valid strings in Python.

Test: Strings - 2 - Question 2

What is the output of the following code snippet?
name = "John"
print(name[1:3])

Detailed Solution for Test: Strings - 2 - Question 2

The slice notation name[1:3] returns the characters at index 1 and 2 of the string name, excluding the character at index 3. Therefore, the output is "oh".

Test: Strings - 2 - Question 3

Which method is used to determine the length of a string in Python?

Detailed Solution for Test: Strings - 2 - Question 3

The len() function is used to determine the length of a string. It returns the number of characters in the string.

Test: Strings - 2 - Question 4

Which of the following methods is used to remove leading and trailing whitespaces from a string in Python?

Detailed Solution for Test: Strings - 2 - Question 4

The strip() method is used to remove leading and trailing whitespaces from a string in Python. It does not modify the original string but returns a new string with the whitespaces removed.

Test: Strings - 2 - Question 5

What does the join() method do in Python?

Detailed Solution for Test: Strings - 2 - Question 5

The join() method is used to join the elements of a list into a single string. It takes a list as an argument and returns a string where the elements of the list are concatenated with the specified separator.

Test: Strings - 2 - Question 6

What is the output of the following code snippet?
text = "Hello, World!"
print(text.upper())

Detailed Solution for Test: Strings - 2 - Question 6

The upper() method returns a new string where all the characters are converted to uppercase. In this case, the output is "HELLO, WORLD!".

Test: Strings - 2 - Question 7

What is the output of the following code snippet?
message = "Welcome to Python"
print(message.split())

Detailed Solution for Test: Strings - 2 - Question 7

The split() method is used to split a string into a list of substrings based on the specified delimiter. If no delimiter is provided, it splits the string at whitespace characters by default.

Test: Strings - 2 - Question 8

What is the output of the following code snippet?
text = "Hello, World!"
print(text.replace("o", "i"))

Detailed Solution for Test: Strings - 2 - Question 8

The replace() method is used to replace occurrences of a specified substring with another substring. In this case, the output is "Helli, World!" because all occurrences of "o" are replaced with "i".

Test: Strings - 2 - Question 9

What is the output of the following code snippet?
text = "Python is fun"
print(text.startswith("Java"))

Detailed Solution for Test: Strings - 2 - Question 9

The startswith() method is used to check if a string starts with a specified prefix. In this case, the output is False because the string "Python is fun" does not start with "Java".

Test: Strings - 2 - Question 10

What is the output of the following code snippet?
text = "Python is fun"
print(text.find("is"))

Detailed Solution for Test: Strings - 2 - Question 10

The find() method returns the index of the first occurrence of a specified substring in a string. If the substring is not found, it returns -1. In this case, the substring "is" is found at index 7.

Test: Strings - 2 - Question 11

Which of the following methods can be used to convert a string into a list in Python?

Detailed Solution for Test: Strings - 2 - Question 11

The split() method is used to split a string into a list of substrings based on the specified delimiter. It returns a list of substrings.

Test: Strings - 2 - Question 12

What is the output of the following code snippet?
text = "Hello,World"
print(text.split(","))

Detailed Solution for Test: Strings - 2 - Question 12

The split() method is used to split a string into a list of substrings based on the specified delimiter. In this case, the string is split at the comma (",") character, resulting in the list ['Hello', 'World'].

Test: Strings - 2 - Question 13

What is the output of the following code snippet?
text = "Hello, World!"
print(text[::-1])

Detailed Solution for Test: Strings - 2 - Question 13

The slice notation [::-1] is used to reverse a string. In this case, the output is "dlroW ,olleH" because the original string "Hello, World!" is reversed.

Test: Strings - 2 - Question 14

What is the output of the following code snippet?
text = "Hello, World!"
print(text.count("o"))

Detailed Solution for Test: Strings - 2 - Question 14

The count() method is used to count the number of occurrences of a specified substring in a string. In this case, the substring "o" appears three times in the string "Hello, World!".

Test: Strings - 2 - Question 15

What is the output of the following code snippet?
text = "Python is fun"
print(text[7:])

Detailed Solution for Test: Strings - 2 - Question 15

The slice notation [7:] returns a substring starting from index 7 until the end of the string. In this case, the output is "is fun".

49 videos|38 docs|18 tests
Information about Test: Strings - 2 Page
In this test you can find the Exam questions for Test: Strings - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Strings - 2, EduRev gives you an ample number of Online tests for practice

Up next

49 videos|38 docs|18 tests
Download as PDF

Up next

Download the FREE EduRev App
Track your progress, build streaks, highlight & save important lessons and more!