Is it bad practice to have a variable that has the same name as a function?
28th September 2012
My answer to Is it bad practice to have a variable that has the same name as a function? on Quora
Yes, it’s definitely not a good idea. In Python functions and variables share the same namespace, so if you create a variable with the same name as a function you won’t be able to call that function.
(I admit I do break this rule occasionally when the variable scope is short enough that I’m certain it won’t cause any problems... but I shouldn’t. Do what I say, not what I do!)
More recent articles
- Qwen2.5-Coder-32B is an LLM that can code well that runs on my Mac - 12th November 2024
- Visualizing local election results with Datasette, Observable and MapLibre GL - 9th November 2024
- Project: VERDAD - tracking misinformation in radio broadcasts using Gemini 1.5 - 7th November 2024