What is the output of the following code:
string = "Python"
print(string[1:])
print(string[1:])
A. ython
B. P
y
t
h
o
n
C. Python
D. ytho
Answer: Option D
Solution (By Examveda Team)
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".
Join The Discussion
Comments (2)
Related Questions on Strings in Python
Which of the following is the correct way to create a string in Python?
A. "Hello, World!"
B. 'Hello, World!'
C. "Hello, World!'
D. 'Hello, World!"
What does the len() function do when applied to a string?
A. Returns the length of the string
B. Converts the string to lowercase
C. Converts the string to uppercase
D. Removes leading whitespace
Which character is used to access individual elements of a string by index in Python?
A. . (period)
B. , (comma)
C. : (colon)
D. [ and ] (square brackets)

here d option is wrong because string start from index one but end at last index.
it contains all the character except p.
Most of the answers are wrong. Please check it once.