0
Extra terristrial
x =str(input()) y=x[100::-1] print(y) How this code is working?? š§š§
3 Answers
+ 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]
+ 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.
+ 2
š¤©Thanks for answering