Variables and operators are the building blocks of every Python program. This chapter deepens Class 7 concepts — variable naming rules, more data types, all operator categories, expressions, and type conversions.
Naming rules: start with letter or _, no spaces, no keywords. Snake_case preferred (my_name). Python is dynamically typed: x = 10 (int), x = "hello" (now str). Data types: int (whole numbers), float (decimals), str (text in quotes), bool (True/False). Check type: type(x). Convert: int("5"), str(42), float(7), bool(0) → False.
Arithmetic: + − * / // % **. Comparison: == != < > <= >= (return True/False). Logical: and, or, not. Assignment: = += -= *= /= //= %= **=. Expressions: combination of values and operators → result. Precedence: parentheses > ** > unary - > * / // % > + -. Example: 2 + 3 * 4 = 14 (not 20). Use parentheses for clarity: (2 + 3) * 4 = 20.
Dynamic typing means a variable's type is determined at runtime, not in advance. You can write x = 5 (integer) and later x = "hello" (string) — Python allows this. Languages like Java/C++ are statically typed: you must declare the type (int x = 5) and cannot change it. Dynamic typing makes Python flexible and quick to write, but you must be careful about unexpected type changes causing errors.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →