Labs ICT
๐ŸŽ“ SIWES/IT Login

Learn Python

3 min read | Python Tutorial
๐ŸŽ“

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

So You Want to Learn Python

So you want to learn Python. Excellent choice. Python is one of the most beginner-friendly yet powerful programming languages in the world. It powers everything from simple scripts to artificial intelligence systems, web applications, data analysis, and even space exploration at NASA.

What makes Python special is its philosophy: code should be readable and beautiful. The language was designed so that you can focus on solving problems instead of wrestling with complicated syntax. Whether you want to build a website, analyze data, automate boring tasks, or dive into machine learning, Python has your back.

Hello, World!

Every programming journey starts with a tradition: making the computer say hello. In Python, this is almost comically simple:

print("Hello, World!")

That's it. One line. No semicolons, no classes, no ceremony. Run it and you'll see Hello, World! printed right to your screen.

Installing Python

Before you write your first line of Python, you need to install it on your computer. Visit python.org/downloads and download the latest version. During installation on Windows, make sure to check "Add Python to PATH" โ€” this lets you run Python from any terminal.

After installation, open a terminal and verify Python is working:

python --version

You should see something like Python 3.12.0. If you see a version number, you're ready to start coding.

Variables and Data Types

Variables in Python are created the moment you assign a value to them. No need to declare types โ€” Python figures it out for you:

name = "Alice"          # str (string)
age = 25                # int (integer)
height = 5.7            # float (decimal)
is_student = True       # bool (boolean)

print(f"Name: {name}, Age: {age}")

Python has several built-in data types you'll use constantly:

  • Strings โ€” text data enclosed in quotes: "hello" or 'hello'
  • Integers โ€” whole numbers: 42, -7, 0
  • Floats โ€” decimal numbers: 3.14, -0.5
  • Booleans โ€” True or False values
  • Lists โ€” ordered collections: [1, 2, 3]
  • Dictionaries โ€” key-value pairs: {"name": "Alice", "age": 25}

Working with Lists

Lists are one of the most versatile data structures in Python. They can hold any type of data and can be easily modified:

fruits = ["apple", "banana", "cherry"]
fruits.append("date")        # add to end
fruits.insert(1, "blueberry") # insert at position
fruits.remove("banana")      # remove by value

print(fruits[0])     # first item: "apple"
print(len(fruits))   # length: 3

# Loop through a list
for fruit in fruits:
    print(fruit)

List comprehensions provide a concise way to create new lists from existing ones:

numbers = [1, 2, 3, 4, 5]
squares = [n ** 2 for n in numbers]
print(squares)  # [1, 4, 9, 16, 25]

Functions

Functions let you organize code into reusable blocks. Define them with the def keyword:

def greet(name):
    return f"Hello, {name}!"

def calculate_area(length, width):
    return length * width

print(greet("Alice"))
print(calculate_area(5, 3))

Functions can have default parameters and can accept any number of arguments:

def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

print(greet("Alice"))                  # Hello, Alice!
print(greet("Bob", "Good morning"))    # Good morning, Bob!

Control Flow

Python uses if, elif, and else for conditional logic. Indentation is required โ€” use 4 spaces consistently:

temperature = 75

if temperature > 90:
    print("It's hot outside")
elif temperature > 70:
    print("It's nice outside")
elif temperature > 50:
    print("It's cool outside")
else:
    print("It's cold outside")

For loops iterate over sequences, while loops repeat until a condition is false:

# For loop
for i in range(5):
    print(i)  # 0, 1, 2, 3, 4

# While loop
count = 0
while count < 5:
    print(count)
    count += 1

๐Ÿงช Quick Quiz

Who created Python?