Python For Beginner

● What is Python?
Python is a high-level, interpreted programming language known for its
simplicity and readability. It is widely used in web development, data
analysis, machine learning, automation, and more.
Why Learn Python?
○ Beginner-friendly syntax
○ Extensive libraries and frameworks
○ Strong community support
○ Versatile for various applications
Setting Up Python on Linux and Windows: Step-by-Step
Guide

  1. Install Python
    On Windows
    ● Download Python
    ○ Visit python.org and download the Windows installer.
    ○ Choose the appropriate version (32-bit or 64-bit) based on your
    system.
    ● Install Python
    ○ Run the installer.
    ○ Check the box “Add Python to PATH” to make Python accessible
    from the Command Prompt.
    ○ Choose Customize Installation for optional features like pip, IDLE,
    and development tools.
    ○ Complete the installation process.
    ● Verify Installation ○ Open Command Prompt.Run:
  2. python –version
  3. pip –version
  4. On Linux
  5. Update System Packages
  6. sudo apt update && sudo apt upgrade -y # For Debian/Ubuntu
  7. ● Install Python
  8. For Debian/Ubuntu:
  9. sudo apt install python3 python3-pip -y
  10. For Red Hat/CentOS:
  11. sudo yum install python3 python3-pip -y
  12. Verify Installation
  13. python3 –version
  14. pip3 –version
  15. Choose an Editor
    Recommended Editors for Both Linux and Windows
    ● VS Code (Visual Studio Code)
    ○ Download from code.visualstudio.com.
  16. ○ Install the Python Extension for debugging, syntax highlighting, and
  17. more.
  18. Command to install on Linux (Debian/Ubuntu):
  19. sudo apt install code
  20. ● PyCharm
  21. ○ Download from jetbrains.com/pycharm.
  22. ○ Offers a free Community Edition.
  23. ● Jupyter Notebook
  24. Install via pip:
  25. pip install notebook
  26. Launch:
  27. jupyter notebook
  28. Verify Python and Pip Installation
    On Windows
    Open Command Prompt and run:
    python –version
    pip –version
    On Linux
    Open a terminal and run:
    python3 –version pip3 –version
  29. Install Essential Libraries
  30. Set Up Virtual Environments (Optional but
    Recommended)
    On Windows
    Create a virtual environment:
    python -m venv myenv
    Activate the environment:
    myenv\Scripts\activate
    Deactivate with:
    deactivate
    On Linux
    Create a virtual environment:
    python3 -m venv myenv
    Activate the environment:
    source myenv/bin/activate
    Deactivate with:
    deactivate

Install Essential Libraries

Use pip to install Python libraries.
Example Commands
Install libraries:
pip install numpy pandas matplotlib
Upgrade pip:
python -m pip install –upgrade pip # Windows
python3 -m pip install –upgrade pip # Linux

  1. Additional Tips
    ● Linux Users
    ○ Use a package manager like apt or yum to install Python
    dependencies.
    Install build tools if needed:
    sudo apt install build-essential -y
    ● Windows Users
    ○ Use PowerShell or Command Prompt for Python commands.
    ○ Use Windows Subsystem for Linux (WSL) for a Linux-like
    development environment.
    Script Mode: Save a file as script.py and run it with:
    python script.py

Basic Syntax
Hello World
print(“Hello, World!”)
Python Comments
Single-line Comments
Comments in Python begin with a # symbol, and Python will ignore everything
following the # on that line:

print(“Hello, World!”)
Inline Comments
Comments can also be placed at the end of a line, and Python will ignore the rest of the
line:
print(“Hello, World!”) # This is a comment
Multiline Comments
Using Multiple # Symbols
Python does not have a specific syntax for multiline comments. However, you can use
multiple # symbols, one per line:

Python does not have a specific syntax for multiline comments. However, you can use
multiple # symbols, one per line:

This is a comment

written in

more than just one line

print(“Hello, World!”)
Using Triple Quotes for Multiline Comments
Since Python ignores string literals that are not assigned to a variable, you can use triple
quotes (“”” or ”’) to create multiline comments:
“””
This is a comment
written in
more than just one line
“””
print(“Hello, World!”)

kamblenayan826

Leave a Reply

Your email address will not be published. Required fields are marked *