Learn Python Basics and Write Simple Scripts
Before we start coding, we need to set up our Python environment. Python is a versatile and widely used programming language that allows developers to create software for web applications, data science, artificial intelligence, and more. To get started, follow these steps:
python --version. If installed correctly, it will display the Python version.Jupyter Notebook is an interactive environment for writing and executing Python code, making it an excellent tool for beginners.
pip install Jupyter.Jupyter notebook. This will open a web-based notebook interface where you can write and execute Python code interactively.Understanding variables and data types is crucial in programming. Python provides various types of data that are used in real-world applications.
Variables are used to store values that can be reused later. In Python, you don’t need to declare the data type explicitly; Python determines it automatically.
x = 10 # Integer
y = 20.5 # Float
name = "Elias" # String
is_active = True # Boolean
Real-Life Example: Imagine you're managing a store and need to store data about a product.
product_name = "Laptop"
price = 599.99
in_stock = True
quantity_available = 50
int (Integer): Whole numbers (e.g., 5, -10, 100)float (Floating Point): Decimal numbers (e.g., 2.5, -0.99, 3.14)str)
"" or '').message = "Welcome to Python!"bool)
True or False.is_python_fun = Trueshopping_list = ["milk", "eggs", "bread"]coordinates = (10, 20)student = {"name": "Elias", "age": 25, "grade": "A"}complex) useful in engineering and scientific computations.
complex_number = 3 + 4j
print(complex_number.real) # Output: 3.0
print(complex_number.imag) # Output: 4.0
num = 100
num_str = str(num) # Converts integer to string