Python tutorial example programs
- Basics
- Variable and Operators
- Control Statements
- Arrays and Collection
- Datetime
- Regular Expressions
- Functions
- OOP
- Classes and Object
- Exception Handling
- Modules
- I/O
- Multithreaded Programming
- Tkinter - Desktop app developement
- Networking
- Database connectivity - MYSQLDB
- CGI(Common Gateway Interface) Programming
- Web programming
- DJango
- Visual Studio Code
In Python, there are widely accepted naming conventions for program files to ensure consistency, readability, and compatibility with other Python modules and libraries. These conventions are based on the guidelines outlined in PEP 8, the Python Enhancement Proposal that defines Python's style guide. Here are the key conventions for naming Python program files:
- Python file names should be written in lowercase letters.
- This avoids conflicts with systems that are case-sensitive (like some Unix-based systems).
Example:
my_program.pydata_analysis.py
- If your file name contains multiple words, separate them with underscores (
_) rather than using spaces, camelCase, or hyphens.
Example:
data_processing.pyuser_authentication.py
- Avoid using special characters (such as
@,#,$, etc.) in file names. Stick to alphanumeric characters and underscores.
Example:
- Correct:
data_cleaning.py - Incorrect:
data@cleaning.py
- Choose file names that clearly describe the purpose or functionality of the script. This helps when the project contains multiple files.
Example:
image_converter.pyfor a script that converts image formats.email_sender.pyfor a script that sends emails.
- Python program files should always use the
.pyextension, which stands for Python.
Example:
main.pyutils.py
- Although it is technically allowed, it's better to avoid starting file names with numbers. This keeps your files more readable and reduces confusion.
Example:
- Correct:
chapter_one.py - Incorrect:
1_chapter.py
- Be cautious when naming your Python files. Avoid naming them after Python’s standard library modules, such as
math.py,datetime.py,string.py, etc., to prevent import conflicts.
Example:
- Correct:
math_operations.py - Incorrect:
math.py
- If your file is intended to be part of a Python package, the package folder should include an
__init__.pyfile (which can be empty or include initialization code). - Package names are generally lowercase as well.
Example:
my_package/__init__.py
data_cleaning.pyprocess_images.pyuser_auth.pycalculate_metrics.py
By following these naming conventions, your Python files will be more organized, readable, and in line with the broader Python community standards.