The chapter in short
Python is a high-level, interpreted language known for readable code. This chapter builds programming skills from variables and data types to collections, functions and files.
It covers operators, input and output, control structures, lists, tuples, dictionaries and sets, defining and calling functions, modules, and simple file handling and error handling.
VariableListTupleDictionaryFunctionException
Key points
- Python uses indentation to mark blocks.
- Lists are mutable; tuples are immutable.
- A dictionary stores key–value pairs.
- def defines a function; return sends a value back.
- import brings in modules such as math and random.
- try/except handles errors without crashing the program.
Definitions
- 1
Variable
A name that refers to a value in memory.
- 2
List
An ordered, mutable collection of items in square brackets.
- 3
Tuple
An ordered, immutable collection of items in round brackets.
- 4
Dictionary
An unordered collection of key–value pairs.
- 5
Function
A named block of code that performs a task and can be reused.
- 6
Exception
An error detected while a program is running.
Formulas
Function
def area(r): return 3.14 * r * r
Loop over a list
for x in [1, 2, 3]: print(x)
Dictionary
marks = {"Ali": 90, "Sara": 85}