parent
19a2ecc0ba
commit
bd35596a51
1 changed files with 130 additions and 0 deletions
@ -0,0 +1,130 @@ |
|||||||
|
title : Python 101 |
||||||
|
author: zvevqx |
||||||
|
published: 2025-11-22 |
||||||
|
cat: code , python |
||||||
|
desc: ressources for python |
||||||
|
|
||||||
|
... |
||||||
|
|
||||||
|
|
||||||
|
# Python for Beginners |
||||||
|
|
||||||
|
## Introduction |
||||||
|
|
||||||
|
Python is a high-level, interpreted programming language known for its readability and simplicity. It is a great language for beginners due to its straightforward syntax and wide range of applications. |
||||||
|
|
||||||
|
## Getting Started |
||||||
|
|
||||||
|
1. **Install Python**: Download and install Python from the official website. It's available for Windows, macOS, and Linux. [Python Downloads](https://www.python.org/downloads/) |
||||||
|
|
||||||
|
2. **Install a Text Editor or IDE**: A text editor or IDE is where you'll write and run your Python code. Some popular options include IDLE (included with Python), Visual Studio Code, and PyCharm. |
||||||
|
|
||||||
|
## Basic Python Concepts |
||||||
|
|
||||||
|
### Variables |
||||||
|
|
||||||
|
Variables are used to store data. They can hold different types of values, like numbers, strings, and lists. |
||||||
|
|
||||||
|
```python |
||||||
|
x = 10 # integer |
||||||
|
y = "Hello, World!" # string |
||||||
|
z = [1, 2, 3] # list |
||||||
|
``` |
||||||
|
|
||||||
|
### Functions |
||||||
|
|
||||||
|
Functions are reusable blocks of code that perform a specific task. They help break down complex programs into smaller, more manageable parts. |
||||||
|
|
||||||
|
```python |
||||||
|
def greet(name): |
||||||
|
print(f"Hello, {name}!") |
||||||
|
|
||||||
|
greet("Alice") # prints "Hello, Alice!" |
||||||
|
``` |
||||||
|
|
||||||
|
### Control Flow |
||||||
|
|
||||||
|
Control flow statements, like if/else and for/while loops, determine the order in which code is executed. |
||||||
|
|
||||||
|
```python |
||||||
|
for i in range(5): |
||||||
|
print(i) # prints numbers from 0 to 4 |
||||||
|
|
||||||
|
x = 10 |
||||||
|
if x > 0: |
||||||
|
print("x is positive") # prints "x is positive" |
||||||
|
``` |
||||||
|
|
||||||
|
### Data Structures |
||||||
|
|
||||||
|
Python has several built-in data structures, including lists, tuples, and dictionaries. |
||||||
|
|
||||||
|
```python |
||||||
|
my_list = [1, 2, 3] # list |
||||||
|
my_tuple = (1, 2, 3) # tuple |
||||||
|
my_dict = {"name": "Alice", "age": 30} # dictionary |
||||||
|
``` |
||||||
|
|
||||||
|
### Modules |
||||||
|
|
||||||
|
Modules are files containing Python definitions and statements. They allow you to organize and reuse code. |
||||||
|
|
||||||
|
```python |
||||||
|
import math |
||||||
|
|
||||||
|
print(math.sqrt(16)) # prints 4.0 |
||||||
|
``` |
||||||
|
|
||||||
|
## Intermediate Python Concepts |
||||||
|
|
||||||
|
### Object-Oriented Programming |
||||||
|
|
||||||
|
Python supports object-oriented programming (OOP), which is a programming paradigm that uses "objects" to design applications. |
||||||
|
|
||||||
|
```python |
||||||
|
class Dog: |
||||||
|
def __init__(self, name, age): |
||||||
|
self.name = name |
||||||
|
self.age = age |
||||||
|
|
||||||
|
def bark(self): |
||||||
|
print("Woof!") |
||||||
|
|
||||||
|
my_dog = Dog("Fido", 5) |
||||||
|
my_dog.bark() # prints "Woof!" |
||||||
|
``` |
||||||
|
|
||||||
|
### Exception Handling |
||||||
|
|
||||||
|
Exception handling in Python is done using try/except blocks. |
||||||
|
|
||||||
|
```python |
||||||
|
try: |
||||||
|
x = 1 / 0 |
||||||
|
except ZeroDivisionError: |
||||||
|
print("Cannot divide by zero!") |
||||||
|
``` |
||||||
|
|
||||||
|
### File I/O |
||||||
|
|
||||||
|
Python can read from and write to files using the built-in `open()` function. |
||||||
|
|
||||||
|
```python |
||||||
|
with open("myfile.txt", "w") as file: |
||||||
|
file.write("Hello, World!") |
||||||
|
|
||||||
|
with open("myfile.txt", "r") as file: |
||||||
|
print(file.read()) # prints "Hello, World!" |
||||||
|
``` |
||||||
|
|
||||||
|
## References |
||||||
|
|
||||||
|
- [Python Documentation](https://docs.python.org/3/) |
||||||
|
- [Python Variables](https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming) |
||||||
|
- [Python Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions) |
||||||
|
- [Python Control Flow](https://docs.python.org/3/tutorial/controlflow.html) |
||||||
|
- [Python Data Structures](https://docs.python.org/3/tutorial/datastructures.html) |
||||||
|
- [Python Modules](https://docs.python.org/3/tutorial/modules.html) |
||||||
|
- [Python Object-Oriented Programming](https://docs.python.org/3/tutorial/classes.html) |
||||||
|
- [Python Exception Handling](https://docs.python.org/3/tutorial/errors.html) |
||||||
|
- [Python File I/O](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files) |
||||||
Loading…
Reference in new issue