
In this lecture, you will learn about keywords that cannot be used as variables and names that are best avoided.
Keywords that cannot be used as variables
The following keywords cannot be used as variable names.
- def
- class
- is
- None
- True
- False
- and
- not
- in
- or
- global
- nonlocal
- lambda
- from
- import
- as
- return
- pass
- with
- assert
- async
- await
- yield
- del
- for
- while
- if
- elif
- else
- try
- except
- finally
- break
- continue
- raise
These keywords have special meanings in Python and cannot be used as variables. For example, “def” is a keyword used to define functions, and “for” is used to repeat a process. You don't need to memorize all of the above keywords here. You will naturally learn them as you progress through the lectures. For now, remember that “words designated as keywords cannot be used.”
Also, if there is even one character difference from the above keywords, it can be used as a variable name.
- _global (先頭にアンダーバーを追加)
- global_address (単語の連結)
- Global (先頭の文字が大文字)
- sync (← 先頭のaがない)
As shown above, Python distinguishes keywords by connecting words or adding an underscore at the beginning, allowing them to be used.
Names that should not be used as variables (Built-in Functions)
Names that should not be used as variables include the names of built-in functions.
Built-in functions are functions that are already provided in Python. For example, the “print” function we have been using so far is also a built-in function.
(Functions will be explained in detail in a separate lecture, so for now, just remember to “avoid using the names of built-in functions.”)
A list of built-in functions can be found at the following website.
https://docs.python.org/3/library/functions.html
- abs
- aiter
- all
- anext
- any
- ascii
- bin
- bool
- breakpoint
- bytearray
- bytes
- callable
- chr
- classmethod
- compile
- complex
- delattr
- dict
- dir
- divmod
- enumerate
- eval
- exec
- filter
- float
- format
- frozenset
- getattr
- globals
- hasattr
- hash
- help
- hex
- id
- input
- int
- isinstance
- issubclass
- iter
- len
- list
- locals
- map
- max
- memoryview
- min
- next
- object
- oct
- open
- ord
- pow
- property
- range
- repr
- reversed
- round
- set
- setattr
- slice
- sorted
- staticmethod
- str
- sum
- super
- tuple
- type
- vars
- zip
- __import__
Although the above built-in function names can be used as variables without causing an error at runtime, they will lose their original function.
For example, after assigning “10” to the variable “print,” try executing “print(‘Hello’).”
(In the author's environment, we will use “sec01_learning02_variables.py” used in the previous lecture.)
print = 10
print('Hello')

Now, execute the above code (F5
).
This will result in the error shown in the figure below.

The error message is “‘int’ object is not callable.” ‘int’ is short for ‘integer’ and refers to an integer such as 10.
The reason why this error occurs is that when the “print = 10” process was executed, the integer “10” was recorded, causing the original “display characters” function to be lost. (Originally, the information necessary to execute the “display characters” process was recorded, but it was overwritten by the information “10”.)
Since “print” has been replaced with the value “10,” the code “print(‘Hello’)” is equivalent to executing the command “10(‘Hello’).” In Python, you cannot execute a process by adding parentheses after an integer, which is why an error occurs.
Since such problems may occur, avoid using the names of built-in functions as variable names. If you cannot think of any other candidates, add an underscore at the beginning to distinguish them. For example, simply changing “type” to “_type” will allow Python to distinguish between them.

If the process stops midway as described above, you can stop the process and clear the error message by clicking the “Stop” button in the icons displayed at the top of the screen.