Python Getting Started
Introduction to Python
Python is one of the most popular and beginner-friendly programming languages in the world. Known for its clean syntax and readability, Python is widely used in web development, data analysis, artificial intelligence, scientific computing, automation, and much more.
Why Learn Python?
Easy to Learn and Use: Python has a simple syntax similar to English, making it perfect for beginners.
- Versatile: From web applications to machine learning, Python is used in a variety of domains.
- Large Community: Python has a supportive community and a wealth of libraries and frameworks.
- High Demand: Python developers are in high demand across industries.
Installing Python
To write and run Python programs, you need to have Python installed on your computer.
Step 1: Download Python
Visit the official Python website: https://www.python.org/downloads/
Click the download button for your operating system (Windows, macOS, or Linux).
Step 2: Install Python
Run the installer and make sure to check the box that says “Add Python to PATH” before clicking "Install Now". This allows you to run Python from the command line.
To verify the installation:
- Open your terminal (Command Prompt or Terminal)
- Type:
python --version
or
python3 --version
You should see something like:
Python 3.9.6
Running Python Code
There are several ways to run Python code:
1. Using the Interactive Shell
After installation, you can open the Python interpreter by typing:
python
This opens the interactive mode where you can type and run Python code directly.
Example:
print("Hello, Python!")
2. Using a Python File (.py)
You can also write your code in a file with the .py
extension. For example, create a file named hello.py
:
print("Hello, World!")
Then run the file using:
python hello.py
Python Syntax Basics
Python code is written with an emphasis on readability. Here's a simple example:
print("Welcome to Python!")
print()
is a built-in function that outputs text to the screen.- Python does not require semicolons at the end of lines.
- Python uses indentation (whitespace) to define blocks of code (like loops, functions, etc.).
First Steps in Python
Let’s try a few basic Python commands:
# This is a comment
print("Learning Python is fun!")
print(2 + 3) # Output: 5
Comments in Python begin with
#
and are ignored during execution.
Summary
In this lesson, you’ve learned:
- What Python is and why it’s useful.
- How to install Python on your system.
- Different ways to run Python code.
- Basic syntax and structure of a Python program.