0

in python (3.3.3), what is the proper way to name a variable that is already being used?

for example, I want to create the variable input. obviously this will not work as there is a python keyword called input.

assuming I needed a name similar to input, what is the proper way to name it without deviating much from the word input, that is, not using a name like user_input or answer?

4
  • 1
    Why not prefix it with an underscore _? Commented Oct 14, 2014 at 3:56
  • 3
    input is simply a bad variable name. Be more descriptive. Commented Oct 14, 2014 at 4:02
  • @VivekPradhan : Because prefixing with an underscore is conventionally used as a weak "internal use" indicator. See PEP 8. So using an underscore as a suffix is better for this use case, although as JimStewart said, a more descriptive variable name would be better. Commented Oct 14, 2014 at 5:55
  • @PM2Ring, I get your point, thanks for the source. It was helpful :) Commented Oct 14, 2014 at 6:05

1 Answer 1

2

You can use any name even if it is used by a function. What you can't is use keywords like def, class, if, else...

But of course it is not a good practice to replace those names used by functions to avoid confusion.

A known practice is to add a _ to the end: input_, class_...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.