Python online course

Variables and types

Names, assignment, and the built-in types you will use in every script.

A variable is a name bound to a value. Python does not make you declare a type up front. The value you assign decides the type, and you can rebind the same name later.

host = "lab-router"
port = 22
retries = 3
ready = True

Common built-ins: str for text, int and float for numbers, bool for true/false, list for ordered collections, and dict for key/value maps. Check a value with type(host) while you are learning; in real code, names and tests should make the type obvious.

Names that survive review

Use lowercase words separated by underscores. Avoid one-letter names except in a tiny loop. Do not shadow built-ins such as list, str, or id.

Conversion

port = int("22")
label = str(port)
flag = bool(1)

int() throws if the string is not a whole number. Catch that at the edge of a program (user input, a config file) instead of letting a traceback surprise you later.