Python Book

Listen to this Post

You Should Know:

To get started with Python, you can download it from the official website: Get the 2025 book. Here are some basic commands and steps to practice Python:

1. Install Python:

  • On Linux:
    sudo apt-get update
    sudo apt-get install python3
    
  • On Windows:
  • Download the installer from Python Official Site and follow the installation instructions.

2. Verify Installation:

  • Open your terminal or command prompt and type:
    python3 --version
    
  • This should display the installed Python version.

3. Running a Python Script:

  • Create a file named `hello.py` with the following content:
    print("Hello, World!")
    
  • Run the script using:
    python3 hello.py
    

4. Virtual Environment:

  • Create a virtual environment to manage dependencies:
    python3 -m venv myenv
    
  • Activate the virtual environment:
  • On Linux:
    source myenv/bin/activate
    
  • On Windows:
    myenv\Scripts\activate
    

5. Installing Packages:

  • Use `pip` to install packages. For example, to install requests:
    pip install requests
    

6. Basic Python Commands:

  • List all installed packages:
    pip list
    
  • Freeze installed packages into a requirements file:
    pip freeze > requirements.txt
    

7. Practice Code: