Variables and Data Types
Variables and the int, float, str, bool types; arithmetic and division quirks.
A variable is a name bound to a value. In Python you don't declare the type: the language infers it from the value.
The core types:
• int — integers. A nice Python bonus: they never overflow, you can compute with 100-digit numbers;
• float — floating-point numbers, e.g. 3.14;
• str — a string, text in quotes;
• bool — True or False.
Python
Variables and the type function
Arithmetic: + - * , and division in Python has an important subtlety:
• / — regular division, the result is always fractional: 7 / 2 equals 3.5;
• // — integer division: 7 // 2 equals 3;
• % — remainder: 7 % 2 equals 1;
• ** — exponentiation: 2 ** 10 equals 1024.
Contest problems usually need // and %: remember the difference between / and //, it is a classic mistake.
Python
Kinds of division and big numbers
Task: create variables with the values 15 and 4 and print their sum, difference, product, integer quotient and remainder — each on its own line.
Then mark the lesson as completed.