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

Test: Strings - 1 - Software Development MCQ


Test Description

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

Test: Strings - 1 for Software Development 2024 is part of Basics of Python preparation. The Test: Strings - 1 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Strings - 1 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Strings - 1 below.
Solutions of Test: Strings - 1 questions in English are available as part of our Basics of Python for Software Development & Test: Strings - 1 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 - 1 | 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
Test: Strings - 1 - Question 1

Which of the following is the correct way to define a string in Python?

Detailed Solution for Test: Strings - 1 - Question 1

In Python, strings can be defined using single quotes ('') or double quotes (""). Option (b) demonstrates the correct way to define a string.

Test: Strings - 1 - Question 2

What will be the output of the following code?
str = "Python"
print(str[1:4])

Detailed Solution for Test: Strings - 1 - Question 2

The slicing notation str[start:end] is used to extract a substring from a string. In this case, str[1:4] returns the characters at indices 1, 2, and 3, resulting in "yth".

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Strings - 1 - Question 3

Which of the following methods is used to convert a string to uppercase in Python?

Detailed Solution for Test: Strings - 1 - Question 3

The upper() method is used to convert a string to uppercase in Python. It returns a new string with all alphabetic characters converted to uppercase.

Test: Strings - 1 - Question 4

What is the result of the following expression?
"Python" + "Programming"

Detailed Solution for Test: Strings - 1 - Question 4

The + operator is used for concatenating strings in Python. In this case, it concatenates the strings "Python" and "Programming" to form "PythonProgramming".

Test: Strings - 1 - Question 5

How can you determine the length of a string in Python?

Detailed Solution for Test: Strings - 1 - Question 5

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

Test: Strings - 1 - Question 6

What will be the output of the following code?
str1 = "Hello"
str2 = "World"
print(str1 + str2)

Detailed Solution for Test: Strings - 1 - Question 6

The + operator is used to concatenate strings in Python. In this case, it concatenates the strings "Hello" and "World" to form "HelloWorld".

Test: Strings - 1 - Question 7

What will be the output of the following code?
str = "Python Programming"
print(str[7])

Detailed Solution for Test: Strings - 1 - Question 7

In Python, strings can be accessed using indexing. The index starts from 0, so str[7] refers to the character at index 7, which is "P".

Test: Strings - 1 - Question 8

What will be the output of the following code?
str = "Python"
print(str[-2:])

Detailed Solution for Test: Strings - 1 - Question 8

Negative indexing is used to access characters from the end of a string. str[-2:] returns the last two characters of the string "Python", which are "on".

Test: Strings - 1 - Question 9

What will be the output of the following code?
str = "Hello World"
print(str.split())

Detailed Solution for Test: Strings - 1 - Question 9

The split() method splits a string into a list of substrings based on whitespace by default. In this case, it splits the string "Hello World" into the list ['Hello', 'World'].

Test: Strings - 1 - Question 10

What will be the output of the following code?
str = "Python Programming"
print(str.replace("Python", "Java"))

Detailed Solution for Test: Strings - 1 - Question 10

The replace() method replaces occurrences of a specified substring with another substring in a string. In this case, it replaces "Python" with "Java" in the string "Python Programming".

Test: Strings - 1 - Question 11

What will be the output of the following code?
python str = "Hello World" print(str[::-1])

Detailed Solution for Test: Strings - 1 - Question 11

The slicing notation [::-1] is used to reverse a string in Python. In this case, it reverses the string "Hello World" to become "dlroW olleH".

Test: Strings - 1 - Question 12

What will be the output of the following code?
str = "Python Programming"
print(str.index("Prog"))

Detailed Solution for Test: Strings - 1 - Question 12

The index() method returns the index of the first occurrence of a specified substring within a string. In this case, it returns the index of the substring "Prog" in the string "Python Programming", which is 11.

Test: Strings - 1 - Question 13

What will be the output of the following code?
str1 = "Hello"
str2 = "hello"
print(str1 == str2)

Detailed Solution for Test: Strings - 1 - Question 13

String comparisons are case-sensitive in Python. In this case, "Hello" and "hello" are different strings, so the comparison str1 == str2 evaluates to False.

Test: Strings - 1 - Question 14

What will be the output of the following code?
str = "Python Programming"
print(str.count("P"))

Detailed Solution for Test: Strings - 1 - Question 14

The count() method returns the number of occurrences of a specified substring in a string. In this case, it counts the number of occurrences of the letter "P" in the string "Python Programming", which is 1.

Test: Strings - 1 - Question 15

What will be the output of the following code?
 

Detailed Solution for Test: Strings - 1 - Question 15

The startswith() method returns True if a string starts with a specified substring. In this case, "Hello World" starts with "Hello", so the result is True.

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

Top Courses for Software Development

49 videos|38 docs|18 tests
Download as PDF

Top Courses for Software Development