A comprehensive collection of beginner-friendly Python examples demonstrating fundamental programming concepts. Perfect for students, learners, and anyone starting their Python journey.
This repository contains practical, well-documented Python examples that cover:
- ✅ Loops & Conditionals - Control flow and decision making
- ✅ Functions - Creating reusable code with parameters
- ✅ Input/Output - User interaction and data display
- ✅ Data Validation - Checking and validating information
- ✅ String Formatting - Modern Python f-strings
Each example includes explanations, code comments, and sample outputs to help you understand the concepts.
- Quick Start
- Examples Overview
- Installation
- Usage
- Learning Path
- Project Structure
- Contributing
- License
# Clone the repository
git clone https://github.com/yourusername/python-examples.git
cd python-examples
# Run the examples
python examples.pyThat's it! The script will run all examples interactively.
Learn how to use loops and the modulo operator to filter numbers.
for i in range(1, 11):
if i % 2 == 0:
print(i)Output: 2, 4, 6, 8, 10
Concepts: range(), for loop, modulo operator (%), conditionals
Interactive program that validates user age and grants/denies access.
age = int(input("Enter age: "))
if age >= 18:
print("Access Granted")
else:
print("Access Denied")Concepts: input(), type conversion, if-else statements
Demonstrates range checking using compound conditions.
score = 85
if score >= 0 and score <= 100:
print("Valid Score")
else:
print("Invalid Score")Concepts: Compound conditions, logical operators (and)
Introduction to functions with parameters and f-string formatting.
def greet(name, age):
print(f"Hello {name}, you are {age}")
greet("Alice", 25) # Output: Hello Alice, you are 25Concepts: Function definition, parameters, f-strings, reusability
Calling the same function with different arguments.
greet("Bob", 30)
greet("Charlie", 22)Concepts: Function reusability, multiple function calls
- Python 3.6 or higher
-
Clone this repository:
git clone https://github.com/yourusername/python-examples.git cd python-examples -
Verify Python installation:
python --version # or python3 --version -
You're ready to go! No additional dependencies needed.
python examples.py======================================================================
Example 1: Print Even Numbers from 1 to 10
======================================================================
2
4
6
8
10
======================================================================
Example 2: Age-Based Access Control
======================================================================
Enter age: 23
Access Granted
[... more examples ...]
- Example 2 prompts you for input - try different ages!
- Examples 4-5 show how to work with functions
- Clear section headers make it easy to follow along
- ✅ Variables and data types
- ✅ Operators (arithmetic, comparison, logical)
- ✅ Control flow (if-else, loops)
- ✅ Functions and parameters
- ✅ Input/output operations
- 📌 Data structures (lists, dictionaries, tuples)
- 📌 Advanced functions (*args, **kwargs, decorators)
- 📌 Exception handling (try-except blocks)
- 📌 File input/output
- 📌 Object-oriented programming (classes)
- 📌 Modules and packages
python-examples/
│
├── README.md # This file - project documentation
├── examples.py # Main Python script with all examples
├── LICENSE # MIT License
├── .gitignore # Git ignore file
│
└── (Optional)
├── examples/ # Individual example files
│ ├── 01_even_numbers.py
│ ├── 02_access_control.py
│ ├── 03_score_validation.py
│ ├── 04_functions.py
│ └── 05_function_reuse.py
│
└── tests/ # Unit tests
└── test_examples.py
| Type | Example | Description |
|---|---|---|
int |
25 |
Integer numbers |
float |
3.14 |
Decimal numbers |
str |
"Alice" |
Text strings |
bool |
True/False |
Boolean values |
| Operator | Example | Meaning |
|---|---|---|
% |
10 % 3 |
Modulo (remainder) |
== |
x == 5 |
Equal to |
>= |
age >= 18 |
Greater than or equal to |
and |
x > 0 and x < 100 |
Logical AND |
or |
x < 0 or x > 100 |
Logical OR |
# Conditional
if condition:
# do something
else:
# do something else
# Loop
for i in range(1, 11):
print(i)
# Function
def function_name(param1, param2):
return resultContributions are welcome! Here's how you can help:
-
Fork the repository
Click the "Fork" button on GitHub -
Create a feature branch
git checkout -b feature/add-new-example
-
Make your changes
- Add new examples with clear comments
- Update documentation as needed
- Ensure code is clean and well-formatted
-
Commit your changes
git commit -m "Add: New example for list comprehension" -
Push to your fork
git push origin feature/add-new-example
-
Create a Pull Request
- Describe what you've added
- Explain the learning value
- Reference any related issues
- ✨ Add more beginner examples
- 📖 Improve documentation
- 🐛 Fix bugs or errors
- 🧪 Add unit tests
- 🎨 Improve code formatting
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License means:
- ✅ You can use this project freely
- ✅ You can modify and distribute it
- ✅ You must include the license notice
- 💬 Questions? Open an Issue
- 🐛 Found a bug? Report it here
- 💡 Have suggestions? Discussions are welcome!
If this repository helped you learn Python, please consider:
- ⭐ Giving it a star
- 🍴 Forking it for your own use
- 📢 Sharing it with others learning Python
- 👍 Contributing improvements
- v1.0.0 (2024) - Initial release with 5 core examples
- Even numbers loop
- Age validation
- Score validation
- Basic functions
- Extended function usage
Created as a learning resource for Python beginners worldwide.
Questions or feedback? Feel free to open an issue or reach out!