Quark’s Outlines: Python Forbidden Characters

Overview, Historical Timeline, Problems & Solutions An Overview of Python Forbidden Characters What are forbidden characters in Python? Python lets you use many characters to write programs. But some characters cannot appear in code unless they are part of a string or a comment. These are forbidden characters. @ $ ? Forbidden characters are printing ASCII characters that Python does not use in its grammar. If you write one outside a string or comment, Python will stop with a syntax error. Python raises an error if you use a forbidden character in code. price$ = 5 # Error print("Price: $5") # OK The character $ is forbidden in names or expressions, but it is allowed inside strings. What characters are forbidden in Python? As of Python 3, the main forbidden characters are: @ $ ? These characters are part of the printable ASCII set. They are legal in strings and comments, but illegal in code structure. You cannot use them in names, operators, or expressions. Python lets you use forbidden characters only inside strings and comments. # This is a comment with @ and $ text = "Price: $20? Really?" The @ symbol is used only for decorators. You cannot use @ in names or values. The $ and ? characters have no use in Python grammar. If you try, Python stops with a syntax error. Why does Python forbid these characters? Python avoids using ambiguous or noisy symbols. This keeps code easy to read. Characters like ? and $ are common in other languages like Perl or JavaScript. Python does not copy those choices. Forbidden characters are not part of Python’s grammar. They are not used in keywords, operators, or names. Their role is limited to content inside strings or comments. Python protects clarity by leaving some symbols out of the grammar. value? = 7 # Error if cost$ > 10: # Error Python does not allow these expressions. The character itself is valid ASCII, but Python blocks it to prevent confusion. A Historical Timeline of Python Forbidden Characters Why are some symbols not used in Python? Python was designed to be readable and clear. Symbols that add noise or confusion were removed or never included. This timeline shows how Python avoided some common characters found in other languages. People explored many syntax symbols. 1958 — Special characters in math input FORTRAN allowed *, /, and - but avoided punctuation in names. 1972 — Symbol-heavy syntax C used many ASCII symbols, including ?, &, and |, to compact logic and structure. People created Python with fewer symbols. 1991 — No $, ?, or ! in names Python 0.9.0 banned noisy or unclear symbols in names and operators. 2000 — @ added only for decorators Python 2.4 introduced @ in a limited role to mark function wrappers. People kept Python simple and clear. 2010 — No expansion of symbol set Python 3 continued to reject non-essential ASCII characters in grammar. 2025 — Forbidden characters remain unchanged Python avoids adding $, ?, or ! to preserve consistency. Problems & Solutions with Python Forbidden Characters How do forbidden characters affect your code? These characters are not allowed in Python names or operators. They appear often in other languages but will stop your Python code unless placed in strings or comments. Problem 1: Using $ in variable names Problem: You want to name a variable cost$ like in JavaScript. Python gives a syntax error. Solution: Python does not allow $ in names. Use an underscore or another plain name. Python lets you name things using only letters, numbers, and underscores. cost = 20 print("Total cost: $", cost) You can print the $ character as part of a string, but not in the variable name. Problem 2: Trying to use ? in expressions Problem: You want to write a ternary check like x > 0 ? x : -x, but Python stops. Solution: Python does not use ? as a ternary operator. It uses a readable form with if...else. Python uses plain words instead of ? for conditions. x = -5 result = x if x > 0 else -x print(result) This form is clear and uses no forbidden symbols. Problem 3: Using @ outside a decorator Problem: You see @ used in decorators and try to use it in other places. Solution: The @ symbol works only at the top of a function to apply a decorator. Anywhere else, it causes a syntax error. Python uses @ only to apply decorators. @staticmethod def say_hello(): print("Hello") You cannot write value @ 2 or use @ in a name. Problem 4: Copying code from another language Problem: You copy a snippet from a Bash or Perl script that uses $ or ?. Python does not accept it. Solution: Replace all special symbols with plain names, operators, or strings. Python lets you rewrite code using its own symbols and rules. # Bash: if [ $count -eq 0 ]; then echo "None"; fi count = 0 if co

May 12, 2025 - 08:22
 0
Quark’s Outlines: Python Forbidden Characters

Overview, Historical Timeline, Problems & Solutions

An Overview of Python Forbidden Characters

What are forbidden characters in Python?

Python lets you use many characters to write programs. But some characters cannot appear in code unless they are part of a string or a comment. These are forbidden characters.

@   $   ?

Forbidden characters are printing ASCII characters that Python does not use in its grammar. If you write one outside a string or comment, Python will stop with a syntax error.

Python raises an error if you use a forbidden character in code.

price$ = 5  # Error
print("Price: $5")  # OK

The character $ is forbidden in names or expressions, but it is allowed inside strings.

What characters are forbidden in Python?

As of Python 3, the main forbidden characters are:

@   $   ?

These characters are part of the printable ASCII set. They are legal in strings and comments, but illegal in code structure. You cannot use them in names, operators, or expressions.

Python lets you use forbidden characters only inside strings and comments.

# This is a comment with @ and $
text = "Price: $20? Really?"

The @ symbol is used only for decorators.

You cannot use @ in names or values.

The $ and ? characters have no use in Python grammar. If you try, Python stops with a syntax error.

Why does Python forbid these characters?

Python avoids using ambiguous or noisy symbols. This keeps code easy to read.

Characters like ? and $ are common in other languages like Perl or JavaScript. Python does not copy those choices.

Forbidden characters are not part of Python’s grammar. They are not used in keywords, operators, or names. Their role is limited to content inside strings or comments.

Python protects clarity by leaving some symbols out of the grammar.

value? = 7  # Error
if cost$ > 10:  # Error

Python does not allow these expressions. The character itself is valid ASCII, but Python blocks it to prevent confusion.

A Historical Timeline of Python Forbidden Characters

Why are some symbols not used in Python?

Python was designed to be readable and clear. Symbols that add noise or confusion were removed or never included. This timeline shows how Python avoided some common characters found in other languages.

People explored many syntax symbols.

1958 — Special characters in math input FORTRAN allowed *, /, and - but avoided punctuation in names.

1972 — Symbol-heavy syntax C used many ASCII symbols, including ?, &, and |, to compact logic and structure.

People created Python with fewer symbols.

1991 — No $, ?, or ! in names Python 0.9.0 banned noisy or unclear symbols in names and operators.

2000 — @ added only for decorators Python 2.4 introduced @ in a limited role to mark function wrappers.

People kept Python simple and clear.

2010 — No expansion of symbol set Python 3 continued to reject non-essential ASCII characters in grammar.

2025 — Forbidden characters remain unchanged Python avoids adding $, ?, or ! to preserve consistency.

Problems & Solutions with Python Forbidden Characters

How do forbidden characters affect your code?

These characters are not allowed in Python names or operators. They appear often in other languages but will stop your Python code unless placed in strings or comments.

Problem 1: Using $ in variable names

Problem: You want to name a variable cost$ like in JavaScript. Python gives a syntax error.

Solution: Python does not allow $ in names. Use an underscore or another plain name.

Python lets you name things using only letters, numbers, and underscores.

cost = 20
print("Total cost: $", cost)

You can print the $ character as part of a string, but not in the variable name.

Problem 2: Trying to use ? in expressions

Problem: You want to write a ternary check like x > 0 ? x : -x, but Python stops.

Solution: Python does not use ? as a ternary operator. It uses a readable form with if...else.

Python uses plain words instead of ? for conditions.

x = -5
result = x if x > 0 else -x
print(result)

This form is clear and uses no forbidden symbols.

Problem 3: Using @ outside a decorator

Problem: You see @ used in decorators and try to use it in other places.

Solution: The @ symbol works only at the top of a function to apply a decorator. Anywhere else, it causes a syntax error.

Python uses @ only to apply decorators.

@staticmethod
def say_hello():
    print("Hello")

You cannot write value @ 2 or use @ in a name.

Problem 4: Copying code from another language

Problem: You copy a snippet from a Bash or Perl script that uses $ or ?. Python does not accept it.

Solution: Replace all special symbols with plain names, operators, or strings.

Python lets you rewrite code using its own symbols and rules.

# Bash: if [ $count -eq 0 ]; then echo "None"; fi
count = 0
if count == 0:
    print("None")

Do not copy $ or ? into Python code. Translate it to Python syntax.

Problem 5: Using forbidden characters in filenames or imports

Problem: You name a file utils@dev.py or try to import a module named price$. Python fails to load it.

Solution: Python module names must follow identifier rules. Use only letters, numbers, and underscores.

Python lets you use clean names in modules and imports.

# OK filename
utils_dev.py

# OK import
import utils_dev

Avoid @, $, and ? in filenames or folder names if you want Python to use them.

Like, Comment, Share, 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