+ 2

What is happening?

Can you explain me what is happening in this codes?

28th Dec 2024, 10:52 AM
MaziarDX
MaziarDX - avatar
6 Antworten
+ 5
1. Sololearn playground 2. "\" is used to escape character sequences. "\\" should escape the "\". As neither "\s" nor "\spec" is an escape sequence in Python, "\" can safely be interpreted as "\" which may be why the interpreter accepts it without error. 3. text_pro=text does not copy the list. "text_pro" is only a reference to the same list that is stored in "text", hence you are appending to the same list tha tyou are iterating.
28th Dec 2024, 12:43 PM
Lisa
Lisa - avatar
+ 3
This reading will help you understand better the third problem. https://inventwithpython.com/beyond/chapter8.html#calibre_link-172 In short, it is bad to modify an iterable while you are looping at it.
28th Dec 2024, 2:20 PM
Wong Hei Ming
Wong Hei Ming - avatar
29th Dec 2024, 7:21 AM
Muhammad Nouman Ali
Muhammad Nouman Ali - avatar
0
Lisa I didn't understand first one.
30th Dec 2024, 9:05 AM
MaziarDX
MaziarDX - avatar
0
I don't remember the exact explanation of the first one, but it is specific to how sololearn playground handles the code. I'll update you in case I find that discussion again... It happens for code bits in the other programming languages as well.
30th Dec 2024, 10:02 AM
Lisa
Lisa - avatar