Hello World in Python
print() writes text to standard output followed by a newline.
Unlike C++ or Go, there’s no boilerplate — no imports, no main() function, no semicolons.
Python executes top-to-bottom from the first line.
Let’s pass a name in as a command-line argument using sys.argv.
sys.argv is a list where sys.argv[0] is the script name and sys.argv[1] is the first argument.
Try running ./main Alice in the terminal — or just ./main to see the usage message.
f-strings (the f"..." syntax) let you embed expressions directly inside strings using {}.
Now let’s read input interactively from the user using input().
input() prints the prompt, then waits for the user to type something and press Enter.
It always returns a string — use int() or float() to convert if you need a number.
Python’s type system is dynamic — variables don’t need type declarations. Let’s look at the basic types.
Python infers the type from the value you assign.
type(x).__name__ returns the type name as a string — useful for debugging.
The :.2f format spec inside an f-string rounds floats to 2 decimal places.
Python also has excellent multi-line string support with triple quotes.
Triple-quoted strings ("""...""" or '''...''') span multiple lines without escape sequences.
.upper() returns an uppercase copy — strings in Python have many useful built-in methods.
.splitlines() splits on newlines and returns a list.
Finally, let’s look at file I/O — writing and reading a file.