this is a log website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

3.5 KiB

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

  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.

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.

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.

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.

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.

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.

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.

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.

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