33 strings that should not be used as variable names in python

I will go in the order like this.

  1. List the things you shouldn't use
  2. How can I find out from the terminal what I shouldn't use?
  3. How can I check if the variable name I want to use is available?

First, list the things you shouldn't use

First of all, you don't have to remember. When I use it, I get an error saying "invalid syntax". However, isn't there any loss even if you look at it once?

  1. False
  2. None
  3. True
  4. and
  5. as
  6. assert
  7. break
  8. class
  9. continue
  10. def
  11. del
  12. elif
  13. else
  14. except
  15. finally
  16. for
  17. from
  18. global
  19. if
  20. import
  21. in
  22. is
  23. lambda
  24. nonlocal
  25. not
  26. or
  27. pass
  28. raise
  29. return
  30. try
  31. while
  32. with
  33. yield

How to call

If you execute the following code, it will be listed as a list type.

test.py


import keyword
keyword.kwlist

How to check if variable names can be used?

If you execute the following code, the value will be returned as Boolean type. Please note that ** True cannot be used **.

import keyword

keyword.iskeyword('def') #True
keyword.iskeyword('bag') #False

It's a simple memo, but is it important except for large system development? ??

Recommended Posts

33 strings that should not be used as variable names in python
[Python] f strings should be used for embedding strings
Reasons to think that the Greek letters of formulas should be used as variable names as they are
Scripts that can be used when using bottle in Python
A record that GAMEBOY could not be done in Python. (PYBOY)
Investigating what could be used as a Markdown parser in Python
Python standard input summary that can be used in competition pro
Tkinter could not be imported in Python
++ and-cannot be used for increment / decrement in python
Functions that can be used in for statements
[Python] Which should be used, return or return None
I made a familiar function that can be used in statistics with Python
Summary of statistical data analysis methods using Python that can be used in business
Japanese can be used with Python in Docker environment
Key input that does not wait for key input in Python
Python knowledge notes that can be used with AtCoder
[Memorandum] Japanese keys cannot be used in python string.Template.substitute
ANTs image registration that can be used in 5 minutes
What's in that variable (when running a Python script)
list comprehension because operator.methodcaller cannot be used in python 2.5
Operators ++,-cannot be used in python (difference from php)
Can be used in competition pros! Python standard library
Compare strings in Python
Reverse strings in Python
[Redash] Standard library cannot be used in python function
[Django] Field names, user registration, and login methods that can be used in the User model
[Python3] Code that can be used when you want to resize images in folder units
A general-purpose program that formats Linux command strings in python
Processing of python3 that seems to be usable in paiza
Master the type in Python? (When should type check be done)
The story that `while queue` did not work in python
Goroutine (parallel control) that can be used in the field
Goroutine that can be used in the field (errgroup.Group edition)
Packages that should be included
[Python] It seems that global variables cannot be referenced in Multiprocessing
A timer (ticker) that can be used in the field (can be used anywhere)
New features in Python 3.9 (1)-Union operators can be used in dictionary types
The story that 2D list replacement did not work in python
A class that summarizes frequently used methods in twitter api (python)
Python standard module that can be used on the command line
[Python] Do not put Japanese in the path used by OpenCV
I wrote a tri-tree that can be used for high-speed dictionary implementation in D language and Python.
8 Frequently Used Commands in Python Django
Use fabric as is in python (fabric3)
[Python] Basic knowledge used in AtCoder
[python] Script that (should) update pwsh
Extract strings from files in Python
Easy padding of data that can be used in natural language processing
Introducing a library that was not included in pip on Python / Windows
Mathematical optimization that can be used for free work with Python + PuLP
Modules of frequently used functions in Python (such as reading external files)
The eval () function that calculates a string as an expression in python
[Python3] Code that can be used when you want to cut out an image in a specific size