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
- 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: - python –version
- pip –version
- On Linux
- Update System Packages
- sudo apt update && sudo apt upgrade -y # For Debian/Ubuntu
- ● Install Python
- For Debian/Ubuntu:
- sudo apt install python3 python3-pip -y
- For Red Hat/CentOS:
- sudo yum install python3 python3-pip -y
- Verify Installation
- python3 –version
- pip3 –version
- Choose an Editor
Recommended Editors for Both Linux and Windows
● VS Code (Visual Studio Code)
○ Download from code.visualstudio.com. - ○ Install the Python Extension for debugging, syntax highlighting, and
- more.
- Command to install on Linux (Debian/Ubuntu):
- sudo apt install code
- ● PyCharm
- ○ Download from jetbrains.com/pycharm.
- ○ Offers a free Community Edition.
- ● Jupyter Notebook
- Install via pip:
- pip install notebook
- Launch:
- jupyter notebook
- 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 - Install Essential Libraries
- 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
- 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!”)