Python B02 · Lesson 1 of 5

Python Basics

History · Features · Applications · Variables · Data Types · Input & Output

Python was created by Guido Van Rossum and first released in 1991. It is now one of the most widely used programming languages in the world.

1. Features of Python

Your basics.py file lists 9 key features:

FeatureWhat it means
InterpretedCode runs line by line — no compilation step needed
Open sourceFree to use, anyone can contribute to Python itself
Cross-platformSame code runs on Windows, Mac, and Linux
Base for AI/MLLibraries like NumPy, TensorFlow, PyTorch are Python-first
Bigger communityHuge ecosystem of tutorials, packages, and forums
Multi-paradigmSupports procedural, OOP, and functional styles
Dynamic typingYou don't declare variable types — Python figures it out
Simple syntaxReads almost like English — easier to learn and read
Extensive librariesThousands of ready-made packages via pip

2. Applications of Python

3. Comments

A comment is a line Python ignores completely. Use # to write one. Comments explain your code for humans.

# This is a comment — Python skips this line
print("Hello World")   # inline comment is also fine
Course note
Your teacher's basics.py starts with # Python Basics and # created by - Guido Van Rossum — those are comments. The actual code is below them.

4. Variables

A variable is a named container that stores a value in memory. Python uses dynamic typing — you don't need to declare the type, just assign a value.

name = "Alice"         # stores a string
age = 25              # stores an integer
height = 5.7          # stores a float
is_student = True    # stores a boolean

Naming rules

5. Data Types

Every value in Python has a type. The 4 core types at this stage:

TypeKeywordExampleNotes
Integerint42, -7Whole numbers, no decimal
Floatfloat3.14, -0.5Numbers with decimal point
Stringstr"hello", 'hi'Text in quotes (single or double)
BooleanboolTrue, FalseOnly two values — capital T and F

Use type() to check a value's type:

print(type(42))       # <class 'int'>
print(type(3.14))     # <class 'float'>
print(type("hi"))    # <class 'str'>
print(type(True))    # <class 'bool'>

6. Type Conversion (Casting)

You can convert between types using built-in functions:

FunctionConverts toExampleResult
int()Integerint("5")5
float()Floatfloat("3.14")3.14
str()Stringstr(42)"42"
bool()Booleanbool(0)False
Common mistake
input() always returns a string, even if the user types a number. You must cast it: int(input("Enter: "))

7. print() and input()

These are Python's basic output and input functions — exactly what your teacher's basics.py demonstrates.

print()

print("Hello World")          # prints text
print(42)                      # prints a number
print("Age:", 25)              # prints multiple values with space
print("Name:" + " Alice")     # concatenation (strings only)

input()

name = input("Enter your name: ")   # shows prompt, waits for user
print("Hello", name)

# Always cast numeric input!
number = int(input("Enter a number: "))
print(number)
From your basics.py
The last two lines of basics.py are exactly this pattern: number = int(input("Enter a number: ")) and print(number)

Drills — Practice

Try each drill on paper or in your code editor. Reveal the answer only after attempting it yourself.

Drill 1 Variables & Types

Write Python code that stores your name in a variable called my_name, your age in my_age, and your height in metres in my_height. Then print all three on separate lines.

my_name   = "Joyal"     # str
my_age    = 20         # int
my_height = 1.75       # float

print(my_name)
print(my_age)
print(my_height)

Each variable stores a different type: str, int, float.

Drill 2 Input & Type Conversion

Ask the user to enter their birth year using input(). Store it as an integer, then calculate and print their age (assume current year is 2026).

birth_year = int(input("Enter your birth year: "))
age = 2026 - birth_year
print("Your age is:", age)

Without int(), the subtraction would fail — you can't subtract a string from a number.

Drill 3 type() Detective

Before running code, predict the output of each type() call below. Write your answers, then check by running the code.

print(type("100"))
print(type(100))
print(type(100.0))
print(type(True))
print(type(int("100")))
# <class 'str'>    — "100" has quotes, so it's a string
# <class 'int'>    — 100 is a whole number
# <class 'float'>  — 100.0 has a decimal point
# <class 'bool'>   — True is a boolean
# <class 'int'>    — int("100") converts the string to integer

Quotes always make something a string, even if it looks like a number.

Quiz — Test Yourself

Score: 0 / 5

1 Who created the Python programming language?

2 What does input() always return, regardless of what the user types?

3 What does dynamic typing mean in Python?

4 Which variable name is invalid in Python?

5 What does print(type(3.14)) output?

Summary

Got a question? Ask your Claude teacher anything about this lesson — variables, types, casting, or anything that wasn't clear. Type your question in the chat.
Next: Operators →