week 1
Week 1: Introduction to Python
Setting up Python & Development Environment
Checking Python Version
import sys print(sys.version)Installing a Package using pip
pip install requestsRunning a Simple Python Script
print("Hello, Python!")Using Virtual Environments
python -m venv my_env source my_env/bin/activate # On macOS/Linux my_env\Scripts\activate # On WindowsUsing IDLE (Python’s Built-in IDE)
python -m idlelibChecking Installed Packages
import pkg_resources installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set} print(installed_packages)Writing a Python Script and Running It Create
hello.py:print("Hello, World!")Run it:
python hello.pyBasic REPL (Read-Eval-Print Loop) Usage
python >>> 5 + 3Installing Jupyter Notebook
pip install notebook jupyter notebookRunning Python from a Jupyter Notebook
print("Running Python in Jupyter Notebook!")
Basic Syntax, Data Types, and Variables
Declaring Variables
Using
type()FunctionString Formatting
Arithmetic Operations
Multi-line Strings
Boolean Logic
User Input
Type Casting
String Slicing
Checking Variable Scope
Last updated