Cheat sheet CBSE · Class 11 · Informatics Practices
Brief Overview of Python
Python basics: identifiers and keywords, data types, operators and their precedence, type conversion, errors, if-elif-else, and for and while loops.
Key ideas
An identifier starts with a letter or _, has only letters, digits and _, is case-sensitive and cannot be a keyword such as for, if, True or None.
Python works out ** first (right to left), then *, /, // and %, then + and −, going left to right; brackets come before all of them.
/ always gives a float (10 / 5 is 2.0); // gives the quotient rounded down and % the remainder.
type() reports int, float, str, bool, list, tuple or dict; lists and dicts are mutable, while int, float, str and tuple are immutable.
input() always returns a str; int(), float() and str() convert explicitly, and int() simply drops the fraction part.
In an if-elif-else ladder only the FIRST true condition runs; indentation shows which lines belong to each block.
range(a, b, c) starts at a, steps by c and stops before b; a while loop repeats as long as its condition is True.
Syntax errors (a missing colon, bad indentation) stop a program before it runs; runtime errors such as ZeroDivisionError or ValueError happen while it runs; logical errors give wrong answers silently.