← Python

Python 1

·Python

Python 01

A quick tour of Python basics: arithmetic, variables, strings, lists, and simple control flow.

Using Python as a calculator

Python can evaluate math expressions directly. Use +, -, *, / for basic arithmetic, and ** for powers. Parentheses control order of operations.

2 + 3
7 * 8
(10 + 5) / 3
2 ** 10

Variables

Store values in names with =. You can reassign a variable, and Python infers the type for you (no int or float declarations needed).

x = 10
y = 3
x + y

x = x + 5
x

Strings and lists

Strings hold text — use quotes. Lists hold ordered collections of items. Indexing starts at 0.

name = "Python"
name.upper()

nums = [1, 2, 3, 4, 5]
nums[0]
nums[-1]
len(nums)

Conditionals, loops, and functions

Use if / elif / else to branch on conditions. Use for to iterate over a sequence. Define reusable logic with def and return.

n = 7
if n % 2 == 0:
    print("even")
else:
    print("odd")

for i in range(3):
    print(i)

def square(x):
    return x * x

square(5)

That’s the core of day-one Python. From here you can explore dictionaries, file I/O, libraries like numpy and pandas, and writing scripts or notebooks for real projects.