Python Forum
Sub: Python-3: Better Avoid Naming A Variable As list ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sub: Python-3: Better Avoid Naming A Variable As list ?
#7
tuple, list, set, dict, ... are builtin types. Their name can be overwritten.
The name is only a reference to an object. A object can have more than one reference.
The assignment to a name, in this case with a dict or a list, let point the name to the new created object.
The old reference to dict and list is no longer there.

To demonstrate this with code:
print(dict)
print(list)

dict = { 'Geeks': 10, 'for': 12, 'Geek': 31 }  
list = []


print(dict)
print(list)

# deleting the names
del dict
del list
# now magically the old types come back
print(dict)
print(list)


# demonstrating syntax highlighting 
value = 42
print(value)
# value is black
# dict and tuple not, because they are built-ins
PS: If you use an IDE or Editor with syntax highlighting, you'll be warned by colors, that you're using a built-in name.
If you look here, you see that dict and list have another color.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Sub: Python-3: Better Avoid Naming A Variable As list ? - by DeaD_EyE - Aug-29-2019, 07:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split string using variable found in a list japo85 2 1,455 Jul-11-2022, 08:52 AM
Last Post: japo85
  naming entities(city abbreviations) tirumalaramakrishna 1 1,357 May-06-2022, 11:22 AM
Last Post: jefsummers
  Avoid third party functions to wrote my python code into system debug-log? mark 9 2,471 Apr-09-2022, 08:41 PM
Last Post: mark
  An IF statement with a List variable dedesssse 3 9,046 Jul-08-2021, 05:58 PM
Last Post: perfringo
  Python Style and Naming Variables rsherry8 3 2,349 Jun-07-2021, 09:30 PM
Last Post: deanhystad
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,857 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Create variable and list dynamically quest_ 12 4,811 Jan-26-2021, 07:14 PM
Last Post: quest_
  Naming the file as time and date. BettyTurnips 3 3,220 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
Question Matching variable to a list index Gilush 17 6,347 Nov-30-2020, 01:06 AM
Last Post: Larz60+
  Python linter Pylance: What does "(variable): List | Unbound" mean? Drone4four 1 6,486 Oct-23-2020, 08:31 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020