Introduction to Python Programming: The Basics You Need to Know

Diya RawatDiya Rawat
4 min read

Introduction

Python is one of the most popular programming languages today, known for its simplicity, readability, and versatility. Whether you're interested in web development, data science, automation, or artificial intelligence, Python is an excellent language to start with. In this blog, we will go over the very basics of Python programming, so you can get started with writing your own Python code!

What is Python?

Python is a high-level programming language designed to be easy to read and write. Unlike other programming languages, Python uses clear and readable syntax, making it beginner-friendly. Python is widely used for:

Web Development (with frameworks like Django and Flask)

Data Science (using libraries like Pandas, NumPy, and Matplotlib)

Automation (automating repetitive tasks)

Artificial Intelligence and Machine Learning

Setting up Python

Before we dive into writing Python code, let’s get Python set up on your computer.

Install Python

  1. Download Python Go to the official Python website: https://www.python.org/downloads/.

The website will typically suggest the latest version for your operating system (Windows, macOS, or Linux). Click on Download Python.

  1. Install an IDE (Integrated Development Environment)

    An IDE is where you'll write and run your Python code. Here are a couple of popular, beginner-friendly options:

Visual Studio Code (VS Code) Download and install VS Code from https://code.visualstudio.com/

After installing, open VS Code and install the Python extension:

Click on the Extensions view icon on the left sidebar (or press Ctrl+Shift+X).

Search for "Python" and click Install.

Once installed, you’re ready to start coding!

Write Your First Python Program

Option 1: Using Python’s Built-in IDE (IDLE) Python comes with its own simple IDE called IDLE. You can launch it from the start menu (Windows) or search for "IDLE" on macOS/Linux.

Once opened, type in:

Run it by pressing F5 or selecting Run > Run Module

Option 2: Using Visual Studio Code Open your IDE (VS Code).

Create a new file called hello.py.

Type in:

save and run the script. In VS Code, you can run it in the terminal.

Basic Python Syntax

  • Variables

    A variable is a name that holds a value. In Python, you don’t need to declare the type of a variable — Python figures that out for you.

    In the example above, age stores an integer value, and name stores a string.

  • Datatypes

    Python has several built-in data types:

    - Integers: Whole numbers (e.g., 5, 100).

    - Floats: Numbers with decimals (e.g., 3.14, 0.5).

    - Strings: Text (e.g., "Hello, World!").

    - Booleans: True or False values.

  • Basic Operators

    You can perform various operations on these data types. For example:

    - Arithmetic Operators: +, -, *, / (addition, subtraction, multiplication, division).

    - Comparison Operators: ==, !=, >, <, >=, <= (to compare values).

    - Logical Operators: and, or, not (to combine conditional statements).

Example:

Control Flow in Python

  • Conditionals (if, else, elif)

    Conditionals allow you to make decisions in your code. The most common conditional statements are if, else, and elif.

    Here, the program checks if the value of age is greater than or equal to 18. If true, it prints "You are an adult." Otherwise, it prints "You are a minor."

  • Loops (for, while)

    Loops allow you to repeat tasks multiple times. The for loop is used when you know how many times you want to repeat a task, and the while loop is used when the number of repetitions is unknown.

    Example of a for loop:

    This will print:

    Example of a while loop:

    This will also print:

Functions in Python

What is a Function?

A function is a block of reusable code that performs a specific task. You define a function using the def keyword.

In this example, the function greet() takes a parameter (name) and prints a message. You can call the function with different arguments to get different outputs.

Conclusion

You’ve now learned how to install Python, set up an IDE, and understand the basics of writing Python code — including variables, data types, operators, conditionals, loops, and functions.

Keep practicing by building small programs and exploring new concepts. Python is powerful and beginner-friendly, and with consistent effort, you’ll be able to create amazing projects in no time.

0
Subscribe to my newsletter

Read articles from Diya Rawat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Diya Rawat
Diya Rawat