+ 1
Isnt it bad style to call a list variable "list" ?
I think it might cause errors. But challanges are full of that.
3 Answers
+ 8
It is bad style and it can seriously damage your code.
For example, you can use "neutral" variable names like this:
a = [1, 2, 3]
b = list((1, 2, 3))
print(a) # [1, 2, 3]
print(b) # [1, 2, 3]
If you use "list" as a variable name, this happens:
list = [1, 2, 3]
b = list((1, 2, 3)) # TypeError, built-in list() method can't be accessed anymore because "list" is now your variable
+ 4
You temporarily use the name 'list' for something different than lists.
You could do list=print, and then list('Hello world.')
And as long as list is used for print, you won't be able to use lists. (You can 'free' lists with del list.)
Unless...
... how about list, print = print, list? :)
Yeah, better not to do this at all imo.
+ 1
thank you Anna
it is a good example.