MrFaws Docs
Learn Python

Fundamentals

Install Python and learn variables, types, input, output and operators.

Run Python

Check your installation with python --version, create a file named hello.py, and run it with python hello.py.

name = "Ada"
age = 28
height = 1.72
is_active = True

print(f"{name} is {age} years old")

The common built-in types are str, int, float, bool and None. Use type(value) while learning to inspect a value.

Input and conversion

input() always returns text. Convert it before doing arithmetic:

price = float(input("Price: "))
quantity = int(input("Quantity: "))
total = price * quantity
print(f"Total: {total:.2f}")

Operators

  • Arithmetic: +, -, *, /, //, %, **
  • Comparison: ==, !=, <, <=, >, >=
  • Logic: and, or, not

Strings

Strings can be sliced, searched and transformed without changing the original value.

message = "  Learn Python  "
clean = message.strip().lower()
print(clean, clean[:5], len(clean))

Exercise

Build a price calculator that asks for price, quantity and discount percentage, then prints subtotal, discount and final total.

On this page