Wlcome to the Learn Python: Beginner to Pro repository! This repository is designed to guide absolute begginers through their python programming journy, starting with basics and progressing to advanced concepts.
Whether you are learning Python for data analysis, web development, or automation, this repository provides clear explanations, real_world examples, practice questions, and coding exercises to help you build a strong foundation.
Python is a versatile and beginner-friendly programming language. It's widely used in web development, data analysis, artificial intelligence, scientific computing, and more. This repository aims to provide you with the knowledge and skills you need to become a Python Hero.
To get started with Python, you need to install Python on your computer. You can download it from the official Python website. Once installed, you can write and run Python code using an Integrated Development Environment (IDE) like PyCharm, VS Code, or even a simple text editor.
Variables are used to store data values. You can think of them as containers for data. For example:
age = 20
name = "Chandrika"
Data types specify the type of data that a variable can hold. Common data types include:
- Integer: Whole numbers (e.g., 42)
- Float: Decimal numbers (e.g., 3.14)
- String: Text (e.g., "Hello, World!")
- Boolean: True or False values (e.g., True)
Operators are symbols that perform operations on variables and values. Common operators include:
- Arithmetic Operators: +, -, *, /
- Comparison Operators: ==, !=, <, >, <=, >=
- Logical Operators: and, or, not
Control flow statements allow you to control the execution of code based on conditions. Common control flow statements include:
- If Statement: Executes code if a condition is true.
if age > 18:
print("You are an adult.")
- For Loop: Iterates over a sequence (e.g., list, string)
for i in range(5):
print(i)
- While Loop: Repeats code as long as a condition is true.
while age < 30:
age += 1
Functions are reusable blocks of code that perform a specific task. You can define a function using the def keyword.
def greet(name):
print(f"Hello, {name}!")
You can call a function by using its name followed by parentheses.
greet("Alice")
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects". Objects are instances of classes, which can have attributes (data) and methods (functions).
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def bark(self):
print("Woof!")
my_dog = Dog("Lucy", 3)
my_dog.bark()
Modules are files containing Python code, and packages are directories containing multiple modules. You can import and use them in your projects.
import math
print(math.sqrt(16))
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
You can read from and write to files using Python's built-in functions.
# Writing to a file
with open("example.txt", "w") as file:
file.write("Howdy!")
# Reading from a file
with open("example.txt", "r") as file:
content = file.read()
print(content)
Exceptions are errors that occur during the execution of a program. You can handle exceptions using try-except blocks.
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero.")
Decorators are a way to modify or extend the behavior of functions or methods. They are commonly used for logging, access control, and caching.
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
Generators are a type of iterable, like lists or tuples, but they generate values on the fly using the yield keyword. They are memory efficient and can be used to handle large datasets.
def my_generator():
yield 1
yield 2
yield 3
gen = my_generator()
for value in gen:
print(value)
Context managers are used to manage resources, such as opening and closing files, in a clean and efficient way using the with statement.
with open("example.txt", "r") as file:
content = file.read()
print(content)
Regular expressions (regex) are patterns used to match character combinations in strings. They are useful for searching, replacing, and validating text.
import re
pattern = r"\d+"
text = "There are 123 apples and 456 oranges."
matches = re.findall(pattern, text)
print(matches) # Output: ['123', '456']
Concurrency and parallelism allow you to perform multiple tasks simultaneously. Concurrency is achieved using threads, while parallelism is achieved using processes.
import threading
def print_numbers():
for i in range(5):
print(i)
thread = threading.Thread(target=print_numbers)
thread.start()
thread.join()
Asynchronous programming allows you to write non-blocking code using async and await keywords. It is useful for I/O-bound tasks like network requests.
import asyncio
async def say_hello():
await asyncio.sleep(1)
print("Hello!")
asyncio.run(say_hello())
Unit testing involves writing tests for individual units of code to ensure they work as expected. The unittest module provides tools for writing and running tests.
import unittest
def add(a, b):
return a + b
class TestAddFunction(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
if __name__ == '__main__':
unittest.main()
Check out the projects directory for hands-on projects that will help you apply what you've learned. Each project comes with detailed instructions and sample code.
- Start from the Basics: Begin with the foundational topics in python Basics and gradually move to advanced sections.
- Practice Regularly: Each section includes coding practice questions to test your understanding.
- Explore Examples: Real-world examples are provided to help you understand how python is used in daily applications.
- Apply your Knowledge: Use the bonus projects to apply what you've learned.
Wlcome contributions to improve this repositoy!
•Found an error? Submiy an issue.
•Have a great example or project? create a pull request.
This repositoy is licensed under the MIT License. Feel free to use, modify, and share this content.
For any questions or suggestions, feel free to open an issue or connect on Github.