Tokens and data types#
Tokens are the smallest units: keywords, identifiers, literals, operators and punctuators.
| Type | Example | Mutable? |
|---|---|---|
| int, float, complex | 10, 3.5, 2+3j | - |
| str | "Rewa" | No |
| list | [1, 2, 3] | Yes |
| tuple | (1, 2, 3) | No |
| dict | {"roll": 1} | Yes (keys must be immutable) |
Operators and precedence#
** (right to left) > unary − > * / // % > + − > relational > not > and > or. Remember // is floor division and % gives the remainder; 7 // 2 = 3, -7 // 2 = -4.
पायथन में list और dict परिवर्तनशील (mutable) हैं, जबकि str और tuple अपरिवर्तनशील (immutable)। ** ऑपरेटर दाएँ से बाएँ हल होता है - 2 ** 3 ** 2 = 2 ** 9 = 512।
Strings and lists - common methods#
Control flow#
if-elif-else, for with range(), while, break, continue. A for loop's else runs only if the loop was not ended by break.
Exam tips#
- Output-prediction questions: trace slicing, negative indices and nested loops carefully.
- Know the difference between
append()andextend(),remove()andpop().