Simon Willison’s Weblog

Subscribe

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!)

This is Is it bad practice to have a variable that has the same name as a function? by Simon Willison, posted on 28th September 2012.

Next: What are the differences between node.js and websockets?

Previous: How do you convince your employer to pay your way to a conference and justify the cost without being able to show something tangible in return?

Monthly briefing

Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.

Pay me to send you less!

Sponsor & subscribe