PyLume logo PyLume
Python basics Open Explainer
* Based on the official Python tutorial

Learn Python first. Then explain your code.

Start with the core ideas from the Python documentation: values, variables, text, lists, decisions, loops, functions, and data structures. When you are ready, open the explainer and paste your code.

Go to Code Explainer
01

Python as a calculator

Python can evaluate expressions with operators like +, -, *, and /. Parentheses control order, and numbers can be integers or decimal values.

02

Variables

A variable stores a value with a name. After assignment, you can reuse that name in later calculations, function calls, or output.

03

Strings

Text values are strings. They can use single or double quotes, can be printed with print(), and can be combined, sliced, or repeated.

04

Lists

Lists keep multiple values in order. You can access items by position, add or remove items, and loop through the list to process each value.

05

Conditions

if, elif, and else let a program choose what to do. This is how code reacts to different inputs or states.

06

Loops

for loops repeat work over a sequence. while loops repeat while a condition remains true.

07

Functions

A function gives a reusable name to a block of code. Inputs go in as parameters, and a result can come back with return.

08

Dictionaries and sets

Dictionaries store key-value pairs. Sets store unique values. Both are useful when you need faster lookup or clean grouping.

EX

Example source code

Read these small programs first, then open the explainer page and paste one to see the step-by-step explanation.

Variables and output

name = "Mukilan"
age = 18

print("Name:", name)
print("Age next year:", age + 1)

Condition

score = 78

if score >= 50:
    print("Pass")
else:
    print("Try again")

Loop through a list

languages = ["Python", "JavaScript", "HTML"]

for language in languages:
    print("I am learning", language)

Function

def add_numbers(a, b):
    total = a + b
    return total

answer = add_numbers(5, 7)
print(answer)

User input

name = input("What is your name? ")

print("Hello", name)

String methods

message = "  python is fun  "

clean = message.strip()
print(clean.upper())

List total

marks = [80, 75, 90]
total = 0

for mark in marks:
    total = total + mark

print("Total:", total)

Dictionary lookup

student = {
    "name": "Kiruthika",
    "grade": "A"
}

print(student["name"])
print(student["grade"])

While loop

count = 1

while count <= 5:
    print(count)
    count = count + 1

Simple try except

text = "42"

try:
    number = int(text)
    print(number + 8)
except ValueError:
    print("Not a number")

Area of a rectangle

length = 12
width = 5

area = length * width
print("Area:", area)

Function with input

def greet(name):
    return "Hello, " + name

user_name = input("Enter your name: ")
message = greet(user_name)
print(message)

Nested condition

age = 20
has_id = True

if age >= 18:
    if has_id:
        print("Entry allowed")
    else:
        print("ID required")
else:
    print("Too young")

Filter even numbers

numbers = [1, 2, 3, 4, 5, 6]
even_numbers = []

for number in numbers:
    if number % 2 == 0:
        even_numbers.append(number)

print(even_numbers)

Count word length

words = ["cat", "python", "code"]

for word in words:
    length = len(word)
    print(word, "has", length, "letters")

Find largest number

scores = [45, 92, 68, 88]
largest = scores[0]

for score in scores:
    if score > largest:
        largest = score

print("Highest score:", largest)

Menu choice

choice = "2"

if choice == "1":
    print("Start game")
elif choice == "2":
    print("Open settings")
else:
    print("Exit")

Simple data processing

sales = [120, 80, 150, 90]
total = sum(sales)
average = total / len(sales)

print("Total sales:", total)
print("Average sale:", average)
Explain these examples

Official source

This beginner summary is adapted from the Python Tutorial sections on the informal introduction, control flow, and data structures.