- #1
- 3,766
- 297
Hopefully someone (chroot??) wil be able to answer this simple Python question.
I am looking at a code written by someone else and there are those two enigmatic statements one after the other:
link0=(0,0,0,0)
pathlist=[link0]
Ok, besides the obvious question of why not initializing directly the list "pathlist" to 0,0,0,0 (it's hard to know what was going in someone's else mind when they were writing the code so I don't worry too much about that point...sometimes code are rewritten and modified over and over before reaching their final form and not everything is rewritten to be the simplest), I have this more to the point question:
what is the difference between defining something within parenthesis (...) and within square brackets [..]? I think that in the second case we are dealing with a list object so that all the corresponding methods (like append) can be used. But what kind of object is (...) ? I am not sure if it simply a string, and if it is I am not sure what the difference is between a string and a list (different methods are defined?)
Thanks in advance!
Patrick
I am looking at a code written by someone else and there are those two enigmatic statements one after the other:
link0=(0,0,0,0)
pathlist=[link0]
Ok, besides the obvious question of why not initializing directly the list "pathlist" to 0,0,0,0 (it's hard to know what was going in someone's else mind when they were writing the code so I don't worry too much about that point...sometimes code are rewritten and modified over and over before reaching their final form and not everything is rewritten to be the simplest), I have this more to the point question:
what is the difference between defining something within parenthesis (...) and within square brackets [..]? I think that in the second case we are dealing with a list object so that all the corresponding methods (like append) can be used. But what kind of object is (...) ? I am not sure if it simply a string, and if it is I am not sure what the difference is between a string and a list (different methods are defined?)
Thanks in advance!
Patrick