Welcome to my Python learning repository! This project contains clean code snippets and simple notes covering the fundamental building blocks of Python programming.
Variables are containers for storing data. Python automatically detects the data type.
name = "Alicade" # String (str)
age = 25 # Integer (int)
height = 5.8 # Float (float)
is_student = True # Boolean (bool)Typecasting is converting a variable from one data type to another.
# Convert string to integer
age_str = "25"
age_int = int(age_str)
# Convert integer to float
price = float(10) # Results in 10.0Used with numeric values to perform common mathematical operations.
addition = 10 + 5 # 15
subtraction = 10 - 5 # 5
multiplication = 10 * 5 # 50
division = 10 / 5 # 2.0
modulus = 10 % 3 # 1 (returns the remainder)Python uses four built-in data types to store collections of data.
Ordered, changeable, and allows duplicate values.
fruits = ["apple", "banana", "cherry"]Ordered, unchangeable, and allows duplicate values.
coordinates = (10.0, 20.0)Unordered, unchangeable*, and unique values only (no duplicates).
unique_numbers = {1, 2, 3, 3, 4} # Stores as {1, 2, 3, 4}| Collection | Ordered? | Changeable? | Duplicates? | Syntax |
|---|---|---|---|---|
| List | Yes | Yes | Yes | [ ] |
| Tuple | Yes | No | Yes | ( ) |
| Set | No | No* | No | { } |
*Set items are unchangeable, but you can remove items and add new items.
- Make sure you have Python Installed.
- Clone this repository:
git clone https://github.com/Alicade123/Python_learning.git
- Run any script using your terminal:
python filename.py