0

Extra terristrial

x =str(input()) y=x[100::-1] print(y) How this code is working?? 🧐🧐

18th Jun 2022, 11:56 AM
Yashwanth Kiran
3 odpowiedzi
+ 3
Yashwanth Kiran , the line that may confuse us is: y=x[100::-1] it is a slice that is applied to the input string stored in x. it is working with positive and negative numbers as slice arguments. i would recommend you to read more about this topic: https://www.learnbyexample.org/JUMP_LINK__&&__python__&&__JUMP_LINK-list-slicing/ => btw: the task description for the mentioned exercise requires to reverse a string. this can be done by just using: y=x[::-1]
18th Jun 2022, 12:54 PM
Lothar
Lothar - avatar
+ 2
X is assigned to the input received. Then element in 100th index and all indexes which comes before of string x are taken , and reversed, then assigned to variable y. Finally it's printed. Extra:- python always takes inputs as strings. You don't need to convert it again to string in line 1.
18th Jun 2022, 1:01 PM
Lae
+ 2
🤩Thanks for answering
19th Jun 2022, 11:59 AM
Yashwanth Kiran