Python Programming - Data Types - Discussion
Discussion Forum : Data Types - General Questions (Q.No. 38)
38.
What will be the output of the following code snippet?
my_string = "Python"
print(my_string[1:5:2])
Answer: Option
Explanation:
The slicing syntax [start:stop:step] is used, selecting characters from index 1 to 5 with a step of 2.
my_string[1:5:2]
slices the string my_string
starting from index 1 (inclusive) up to index 5 (exclusive), with a step size of 2.
So, it selects characters at indices 1 and 3 (1+step-size) (skipping index 5), which are 'y' and 'h' respectively.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers