Python 3.9+Input & outputfunction
keyword.issoftkeyword()
variables
Checks whether a string is a soft keyword (match, case, _, type): it acts as a keyword only in a particular context.
Syntax
keyword.issoftkeyword(s)
A soft keyword stays an ordinary name outside its construct: match = 3 is legal, while inside match/case it is syntax. The list keyword.softkwlist grows between versions: type was added in 3.12 and lazy in 3.15, so the answer for the same word depends on the interpreter. For ordinary keywords the function returns False — iskeyword checks those.
Examples
import keyword
print(keyword.issoftkeyword('match'), keyword.issoftkeyword('if')) # → True False
match = 3 # мягкое ключевое слово можно занять
print(match) # → 3
print(keyword.softkwlist) # → ? список зависит от версии Python
See also
Open in the full glossarydocs.python.orgReport an inaccuracy