What is the output of following Python Code?
s = 'clcoding'
print(s[1:6][1:3])
Solution and Explanation:
Let's break down the expression step by step:
s = 'clcoding': This assigns the string 'clcoding' to the variable s.
s[1:6]: This slices the string from index 1 (inclusive) to index 6 (exclusive), resulting in 'lcod'.
s[1:6][1:3]: This further slices the result of the previous step 'lcod' from index 1 to index 3, resulting in 'co'.
So, the output of print(s[1:6][1:3]) will be 'co'.
0 Comments:
Post a Comment