Python: Getting Started with Basics

Introduction

Python is one of the most popular programming languages today, known for its simplicity and versatility. Whether you’re aiming to automate tasks, build web applications, or dive into data science, Python is a great starting point. In this tutorial, we’ll cover the absolute basics: writing your first program, understanding variables, and working with simple data types.

 

Step 1: Writing your first Python program


Every programmer’s journey begins with the classic Hello, World! program.

In Python, it’s incredibly simple:

 print("Hello, World!")

  • print() is a built-in function that outputs text to the screen.
  • The text inside quotes " " is called a string.


 Try running this in your Python interpreter or IDE. You should see the message appear instantly.

 

Step 2: Variables and Data Types

Variables are like containers that store information. In Python, you don’t need to declare the type explicitly — the interpreter figures it out.

# Assigning values to variables

name = "Deepak"

age = 42

height = 5.9

 

  • name is a string ("Deepak")
  • age is an integer (42)
  • height is a float (5.9)

 

You can print them as below:

print(name)

print(age)

print(height)

 

Python is dynamically typed, meaning you can reassign variables to different types:

age = "Forty Two"

print(age)   # Now age is a string

 

 

 

Step 3: Basic Operations

Python can handle arithmetic easily:

x = 10

y = 3

 

print(x + y)   # Addition 13

print(x - y)   # Subtraction 7

print(x * y)   # Multiplication 30

print(x / y)   # Division 3.333...

print(x // y)  # Floor division 3

print(x % y)   # Modulus 1

print(x ** y)  # Exponentiation 1000

Notice how / gives a float result, while // gives an integer.

 

Step 4: Strings in Action

Strings are powerful in Python. You can join them, slice them, and manipulate them easily.

greeting = "Hello"

name = "Deepak"

 

message = greeting + " " + name

print(message)  # Output: Hello Deepak

 

 

String slicing

print(message[0:5])  # Output: Hello

 

Mini Exercise

Try this yourself:

  1. Create a variable city with the name of your city.
  2. Create a variable year with the current year.
  3. Print a sentence like:

I live in Gurugram and the year is 2025.

Hint: Use the + operator or f-strings:

 

city = "Gurugram"

year = 2025

print(f"I live in {city} and the year is {year}.")

 

Conclusion

In this first tutorial, you learned how to:

  • Write your first Python program
  • Use variables and data types
  • Perform basic arithmetic
  • Work with strings

These are the building blocks of Python. In the next tutorial, we’ll explore control flow — how to make decisions with if statements and repeat actions with loops.