Why the output of this code is 1 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the output of this code is 1 ?

X='abcde' Y= x[-1:] Print(len(y))

7th Feb 2019, 10:18 PM
H.code
2 Answers
+ 3
I suggest you review this and read the comments on each lesson. You would be surprised to find very useful explanations of each topic. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/?ref=app
7th Feb 2019, 10:50 PM
Lambda_Driver
Lambda_Driver - avatar
+ 2
-1 accesses the last element. : after the first and only index means that the iterable will be read from that index to the end. So y holds only the last element. Two recommendations: 1.) Tell us a bit more about your question next time, for example the language; 2.) concentrate on syntax: As you wrote it, your code doesn't run at all, because you mix up capital Y and y, X and x, Print and print.
7th Feb 2019, 10:47 PM
HonFu
HonFu - avatar