47

I'm new to Python. I'm writing some code in Sublime and it highlights the word 'input'

I use it as a variable name and it seems to work, so I wondered whether it may be a keyword in a newer version. (I'm currently using 2.7.5)

Zoltán
  • 20,250
  • 12
  • 87
  • 128
  • 1
    Shouldn't this get downvoted? Putting his exact question into Google comes up with the appropriate doc pages, followed by an explicit site dedicated to answering this question (reserved keywords) – TankorSmash Dec 19 '13 at 00:26
  • 6
    @TankorSmash The fact that it is a built in function doesn't really explain to a newbie like me why it would be highlighted. I come from Java where there are no built in functions. Furthermore, it's not exactly obvious to a newbie like me that sublime thinks it's a method when I give it no parameters or parentheses. – Zoltán Dec 19 '13 at 00:35

1 Answers1

53

No, input is not a keyword. Instead, it is a built-in function.

And yes, you can create a variable with the name input. But please don't. Doing so is a bad practice because it overshadows the built-in (makes it unusable in the current scope).

If you must use the name input, the convention is to place an underscore after it:

input_ = input()
wisbucky
  • 27,562
  • 9
  • 122
  • 88
  • Right-o. Will rename it. Any suggestions though? It's an input to a generic filter function :) – Zoltán Dec 18 '13 at 23:37
  • 1
    @Zoltán - Eh, that's really up to you. I've used `inp` a couple of times. –  Dec 18 '13 at 23:39
  • Right. Python won't stop you from changing what a name that normally refers to a built in function refers to, but it's almost always a bad idea. The built in function still exists, and you can refer to it using `__builtins__` if you really do want to actually change what the function name means but then need access to the builtin. – Peter DeGlopper Dec 18 '13 at 23:41
  • 1
    @Zoltán: not sure what you mean by a filter function, but possible generic names for function parameters are `iterable` or `value` according to whether the input is multiple or single. The inputs to the builtin function `filter` are named `function` and `iterable`. – Steve Jessop Dec 18 '13 at 23:47
  • you could use `inputs` as an alternative variable name – wisbucky Oct 01 '21 at 00:27