How is a copied sub-string different from string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How is a copied sub-string different from string

i copied a string from 1 var to other but it is not equal... why? https://code.sololearn.com/cnKnz4Y92hjX/?ref=app https://code.sololearn.com/cnKnz4Y92hjX/?ref=app

14th Aug 2017, 9:45 AM
akshay
akshay - avatar
1 Answer
- 1
Cause you didn't copied a string. On line 4 you created array (list) of characters. so "Hello"[0] == ["H", "e", "l", "l", "o"][0] (Both are "H"), but the string is not the same as array (list). you may want to try joining list to string: >> "".join(["H", "e", "l", "l", "o"]) == "Hello" so line 4 will look like this: cpy="".join([i for i in msg])
16th Aug 2017, 12:02 AM
Michal Pácal
Michal Pácal - avatar