Quark's Outlines: Python Names & Keywords
**Overview, Timeline, Problems & Solutions**
## Overview of Python Names and Keywords
### What is a name in Python?
A Python name is also called an identifier. A name is a word you use to show a variable, a function, a class, or another object in Python code. A name works like a label you place on a box to show what is inside.
A Python name can use uppercase letters A through Z, lowercase letters a through z, digits 0 through 9, and the underscore character `_`. A name cannot begin with a digit. You can use names like `player1`, `total_score`, or `X`. A name like `1st_place` is not allowed because it starts with a digit.
Python names are case-sensitive. The name `Name` is different from the name `name`. Each one is a separate name in Python.
Python does not set a limit on name length. You can use short names or long names. A short name can help you read and understand code.
**Python lets you name a value.**
This example shows a valid Python name that identifies a value:
score = 100
The name `score` is a valid Python identifier. The name `score` stores the value `100`.
### What characters can you use in Python names?
A Python name is also called an identifier. A Python identifier can use letters, digits, and the underscore character `_`. Within the basic ASCII range, you can use uppercase letters A through Z, lowercase letters a through z, digits 0 through 9, and the underscore character `_`. A Python name cannot begin with a digit.
Python 3 also allows Unicode characters. Unicode characters include letters from other alphabets outside the English language. This means you can use characters like `α` from the Greek alphabet or `Б` from the Cyrillic alphabet, if your Python file uses UTF-8 encoding. UTF-8 is the default encoding in Python.
You cannot use spaces in a Python name. You can use an underscore `_` to show a space. For example, a name like `max_value` can stand for “max value.”
Python does not allow symbols like `@`, `$`, `&`, or `-` in names. These symbols have other meanings in Python code and are not part of valid names.
You can use English letters, digits (after the first character), and the underscore to write Python names.
**You can use underscores when naming in Python.**
This example shows a valid Python name with an underscore:
max_value = 10
The name `max_value` is a valid Python identifier. The underscore connects the two parts of the name. The name `max_value` stores the value `10`.
### What are Python keywords?
A Python keyword is a special word that has a fixed meaning in the language. Python keeps these words to control how code runs. You cannot use a keyword as a name for a variable, a function, or anything else.
Some common Python keywords are `if`, `else`, `for`, `while`, `class`, `def`, `True`, `False`, and `None`. When Python reads one of these words, it knows the word is part of the code structure. For example, the keyword `if` starts a condition. The keyword `True` means a truth value.
**Python gives you an error when you name a keyword.**
Python will not let you assign a value to a keyword. This line will not work:
True = 5
The word `True` is a keyword. Using it as a name will cause a syntax error.
Python keywords are case-sensitive. The word `True` is a keyword. The word `true` is not. You can make a name called `true`, but it will not mean the same thing.
There are a few dozen keywords in Python. Some other examples are `and`, `as`, `assert`, `break`, `continue`, `return`, `import`, `from`, `lambda`, `with`, `try`, `except`, `finally`, `pass`, `yield`, `in`, `is`, `not`, and `or`.
### What are soft keywords in Python?
A soft keyword is a word that works like a keyword only in special situations. In other places, you can use the word as a name.
Python added soft keywords to support new features without blocking names in older code. In Python 3.10, the words `match` and `case` were added as soft keywords. Inside a `match` block, they act like real keywords. Outside that block, they can still be used as names.
**You use match and case with Python’s soft keywords.**
This example shows how `match` and `case` work as soft keywords:
match value:
case 1:
print("one")
The word `match` starts the block. The word `case` checks for a value.
The single underscore `_` is also a soft keyword. In a `match` block, `_` is used as a wildcard. In the Python interpreter, `_` holds the last result. Outside those places, you can use `_` as a name.
In Python 3.12, the word `type` became a soft keyword in pattern matching. You can still use `type` as a name outside that use.
### Are there special patterns for Python names?
Python uses a few name patterns with special meaning.
A name that starts with one underscore, like `_helper`, is meant for internal use. Python skips these names when you write `from module import *`.
A name that is only one underscore, `_`, is used when the name is not important. For example, in a loop like `for _ in range(5):`, you do not use the name, but the loop still runs five times.
A name that starts and ends with two underscores, like `__init__`, is used by Python for built-in actions. These are called double-underscore names. You should not make your own names like this unless Python requires them.
A name that starts with two underscores but does not end with two underscores, like `__secret`, is changed by Python inside a class. Python adds the class name to it. This prevents name conflicts in subclasses.
**Python hides a name when you use double underscores.**
This example shows a double-underscore name inside a class:
class Example:
def __init__(self):
self.__secret = 42
The name `__secret` will be changed by Python to make it harder to access from outside the class.
### Why are names and keywords important to learn in Python?
Python names and Python keywords are the basic parts of the language. A name points to something you create. A keyword controls how code runs.
When you choose a name, you must follow Python rules. When you use a keyword, you must use it the right way. This helps your code work without errors.
Knowing keywords also helps you read code. You know what each part does. You avoid mistakes like using `for` as a name.
**You loop through values with`for` in Python.**
This example shows the keyword `for` and a name used together:
for number in range(3):
print(number)
The keyword `for` starts the loop. The name `number` holds each value from the range.
## Timeline of Python Names and Keywords
**Where do Python’s naming and keyword rules come from?**
Python’s names and keywords reflect a long history. Some parts come from programming languages like ALGOL, C, and ABC. Others come from grammar theory and early computing. This timeline shows how Python’s system of names and keywords took shape.
**1956 — Phrase structure grammar** , Noam Chomsky, gave programming languages formal rules for syntax and naming structure.
**1960 — Structured control keywords** , ALGOL 60, used clear control words like `if`, `then`, and `begin`, setting patterns for block-based code.
**1964 — Long descriptive names** , PL/I, introduced naming rules for large programs with business and scientific terms.
**1972 — Case-sensitive identifiers** , C language, treated `Name` and `name` as different and used short control keywords like `for` and `if`.
**1980 — Clear syntax and indentation** , ABC language, used readable keywords and indentation instead of braces, and shaped Python’s naming and line style.
**1989 — Simple keyword set** , Guido van Rossum, designed early Python to use indentation and a minimal keyword list inherited from ABC and C.
**1991 — Core operators and constants** , Python 0.9.0, introduced `and`, `or`, `not`, `None`, and used the naming rules still used today.
**2000 — New control flow** , Python 2.0, added the keyword `yield` for generator functions, and later `with` for resource cleanup.
**2001 — Style rules for names** , PEP 8, defined community rules for names like `lower_case_with_underscores` and `CapWords`.
**2008 — Reserved truth values** , Python 3.0, turned `True`, `False`, and `None` into keywords and allowed Unicode in names with PEP 3131.
**2015 — Async syntax** , Python 3.5, added `async` and `await` to support asynchronous programming using new keywords.
**2021 — Context-based keywords** , Python 3.10, introduced `match` and `case` as soft keywords for pattern matching blocks.
**2023 — Type-matching keyword** , Python 3.12, added `type` as a soft keyword in match statements, continuing Python’s flexible approach.
**2025 — Slow and stable changes** , Python core team, avoids full new keywords and maintains long-term support for existing names
## Problems and Solutions with Python Names and Keywords
Good naming in Python helps you write code that runs without error and is easy to understand. Python has clear rules for names and reserved words called keywords. These rules prevent confusion. The problems below use everyday examples to explain how Python naming rules work and why they matter. Each problem shows a situation and each solution connects it to Python.
### Problem 1: Following naming rules in a form
You are filling out a form that asks for a username. The form says the name must begin with a letter and can only include letters, numbers, or underscores. You type `12*Star`, but the form rejects it. It begins with a number and uses `*`, which is not allowed. You try again with `Star_12` and the form accepts it.
Python has the same rule for names. A Python name must begin with a letter or an underscore. After that, the name can include letters, numbers, or underscores. No other characters are allowed.
**Python lets you begin names with letters or underscores.**
This example shows two valid Python names:
player1 = "Alice"
_score = 95
The name `player1` begins with a letter. The name `_score` begins with an underscore. Both follow the rules.
### Problem 2: Case-sensitive labels
You are sorting boxes and put a label on one that says `Fragile`. You label another box as `fragile`. You think they are the same. But a helper sees the capital `F` and puts the boxes in different groups. The labels are treated as separate.
Python also treats uppercase and lowercase letters as different. A name like `Time` is not the same as `time`. If you write `Value = 10` and later use `value`, Python does not recognize it. Python sees `value` as a different name or as a name that does not exist.
**You and Python treat name and Name as different.**
This example shows how case affects names in Python:
Name = "box"
name = "crate"
The name `Name` and the name `name` are separate. Python stores them as different names.
### Problem 3: Using a reserved word as a name
You are playing a board game. The game says that if someone says the word `Skip`, the next player misses a turn. You choose the team name `Skip`. During the game, people get confused. They don’t know if you mean the team or the game rule.
Python also has special words called keywords. A keyword has a meaning in Python. You cannot use a keyword as a name. For example, `for` is a keyword used to start a loop. If you write `for = 5`, Python gives an error. It expects `for` to begin a loop, not store a value.
**Python won’t let you name something`for`.**
This example shows what happens when a keyword is used as a name:
for = 5
Python does not allow this. The keyword `for` is reserved.
### Problem 4: Words with special meaning in context
The word `ace` means different things in different places. In a card game, `ace` means a strong card. Outside the game, `ace` can be a nickname. The meaning changes based on the context.
Python uses soft keywords in the same way. A soft keyword is only treated like a keyword in certain places. The words `match` and `case` are soft keywords in Python 3.10 and later. Inside a `match` block, Python treats them as keywords. Outside the block, you can use them as names.
**You can use match and case as names unless Python needs them.**
This example shows how `match` and `case` work in context:
match value:
case 1:
print("one")
The word `match` starts the pattern match. The word `case` checks the value. Python reads these words as keywords only in this block.
### Problem 5: Understanding special name patterns
You see company project codes written as `__DATA__`. You are told not to make names like that. These names are used for official tools. You are also told that if a folder begins with `_`, it is marked as internal. These naming rules are not enforced by the computer, but everyone follows them.
Python uses similar patterns. A name like `__init__` begins and ends with two underscores. This kind of name is used by Python itself. You should not make your own names in this format unless you are using one of Python’s built-in methods.
A name that begins with one underscore, like `_data`, means “internal use.” Python does not stop you from using it, but other programmers will understand that the name is not for general use.
A name that begins with two underscores, like `__secret`, is changed by Python when it is used inside a class. Python adds the class name to the front of the name. This is called name mangling. It protects the name from being used by mistake in other parts of the code.
**When you use double underscores, Python rewrites the name.**
This example shows a special name used inside a class:
class Vault:
def __init__(self):
self.__code = "1234"
The name `__code` is changed by Python so it does not get mixed up with names in other classes. This keeps it protected inside `Vault`.
## Like, Comment, and Subscribe
Did you find this helpful? Let me know by clicking the like button below. I'd love to hear your thoughts in the comments, too! If you want to see more content like this, don't forget to subscribe to my channel. Thanks for reading!
**Mike Vincent** is an American software engineer and writer based in Los Angeles. Mike writes about technology leadership and holds degrees in Linguistics and Industrial Automation. More about Mike Vincent