Hello World
print("Hello, world!")
Run the script:
python main.py
This prints a line in Python with the built-in print function. It is the normal first script example.
Variables
Python variables are dynamically typed and can be annotated when the expected type matters.
name = "Dan"
age: int = 30
is_active = True
Python lets you bind values without declaring a type first. Add annotations when you want the expected shape to be clearer.
Functions
def greet(name: str) -> str:
return f"Hello, {name}!"
message = greet("world")
print(message)
This defines a function with type hints, calls it, and prints the returned value.