- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Introduction / of Python Syntax & Reserved Keywords
Python Syntax and Reserved Keywords
๐น What is Python Syntax?
Python syntax defines how Python code should be written and formatted. If the syntax is incorrect, the Python interpreter will raise errors.
| Rule | Explanation | Example |
|---|---|---|
| Indentation is required | Python uses spaces/tabs instead of braces {} |
|
| Case-sensitive | Name and name are different |
|
| Statements end with newline | No semicolon (;) required |
print("Hello") |
| Comments | Start with # |
# This is a comment |
| Variable declaration | No var keyword, just assignment |
x = 10 |
๐ Python Reserved Keywords
Keywords are special reserved words that cannot be used as variable or function names. They are part of the Python language syntax.
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
You cannot use these keywords as variable names.
They are case-sensitive and used internally by Python.
๐งช Check Keywords in Python
To list all keywords using code:
import keyword
print(keyword.kwlist)
๐ซ Invalid Keyword Usage
Trying to use a keyword as a variable name results in an error:
def = 10 # โ Invalid: 'def' is a reserved keyword
โ Correct way:
my_def = 10