ExamVeda
Login
Home
11
What method is used to convert a string to uppercase in Python?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
12
Which method is used to replace a substring in a string with another substring?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
13
In Python, how can you check if a string starts with a specific substring?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
14
Which method is used to count the occurrences of a substring in a string?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
15
What is the purpose of the strip() method for strings?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
16
What is the output of the following code:
string = "Python"
print(string[::-1])
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
17
What will the following code output:
string = "Python"
print(string.lower())
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: python

Here's why:

The code uses the .lower() method on a string.

The .lower() method is a built-in function in Python for strings.

Its purpose is to convert all uppercase characters in a string to lowercase.

In the given code, the string is "Python".

When string.lower() is executed, it converts the 'P' to 'p'.

All other characters are already in lowercase, so they remain unchanged.

Therefore, the output is "python".
18
In Python, which escape sequence is used to represent a tab character?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
19
What does the isalpha() method of a string object check for?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
20
What is the output of the following code:
string = "Python"
print(string[1:])
Discuss
Answer & Solution
Answer: Option D
Solution:
The correct answer is A: ython.

Here's why:

In Python, strings are sequences, and we can access parts of them using slicing.

The code `string[1:]` creates a slice of the string.

The `1` inside the square brackets means we're starting our slice from the second character of the string (remember, Python uses zero-based indexing, so index 0 is the first character).

The `:` after the `1` means we're going all the way to the end of the string.

So, `string[1:]` takes the string "Python" and returns a new string that starts from the second character ('y') and goes to the end, resulting in "ython".