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

What is the output?

Str="spoyl" x=str [::2] y=str [2]+str [1::2] print (x+y)

14th Feb 2020, 3:08 PM
Devi Kamaraj..😉
Devi Kamaraj..😉 - avatar
6 Answers
+ 8
******************* _________________ Output is: solopy _________________ ******************* # step +2 because str[::2] then.. str="spoyl" | | | 0 2 4 | | | . . . x= s o l _______________ str ="spoyl" | 0 1 2 3 | . str[2] = o ---------- # first index 1 then step +2 because str[1:2] then.. str="spoyl" | | 1 3 | | . . str[1:2]= p y ----------- y = str[2] + str[1:2] y = "opy" _____________________ x + y = "solopy"
14th Feb 2020, 3:32 PM
Pedro H.J
Pedro H.J - avatar
+ 7
Great....thanks a lot
14th Feb 2020, 3:33 PM
Devi Kamaraj..😉
Devi Kamaraj..😉 - avatar
+ 6
I want to know the full explanation...can you define it..thanks for your response
14th Feb 2020, 3:18 PM
Devi Kamaraj..😉
Devi Kamaraj..😉 - avatar
+ 6
Devi Kamaraj..😉 Did you understand ?
14th Feb 2020, 3:39 PM
Pedro H.J
Pedro H.J - avatar
+ 6
Yes...of course...its clear...thanks 😊
15th Feb 2020, 1:10 AM
Devi Kamaraj..😉
Devi Kamaraj..😉 - avatar
+ 5
Change Str to str. Run this code https://code.sololearn.com/cxHFj1AJNp5g/?ref=app
14th Feb 2020, 3:16 PM
Pedro H.J
Pedro H.J - avatar