0
0
Pythonprogramming~10 mins

Numeric values (int and float behavior) in Python - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Numeric values (int and float behavior)
Start
Assign int or float
Use in expressions
Operations: +, -, *, /
Result type depends on operands
End
This flow shows how Python handles numbers: assigning integers or floats, using them in math, and how results keep or change types.
Execution Sample
Python
a = 5
b = 2
c = a / b
d = a // b
e = a + 0.5
Assign integers and floats, then do division (normal and floor) and addition with float.
Execution Table
StepActionVariablesResultNotes
1Assign a = 5a=55a is integer
2Assign b = 2a=5, b=22b is integer
3Calculate c = a / ba=5, b=22.5Division / always float
4Calculate d = a // ba=5, b=22Floor division // truncates to int
5Calculate e = a + 0.5a=5, e=5.55.5int + float = float
6Enda=5, b=2, c=2.5, d=2, e=5.5-All variables assigned
💡 All operations done; variables hold expected int or float values.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
aundefined555555
bundefinedundefined22222
cundefinedundefinedundefined2.52.52.52.5
dundefinedundefinedundefinedundefined222
eundefinedundefinedundefinedundefinedundefined5.55.5
Key Moments - 3 Insights
Why does division (/) result in a float even if both numbers are integers?
Because Python's / operator always returns a float to keep decimal precision, as shown in step 3 where 5 / 2 gives 2.5.
What is the difference between / and // operators?
The / operator returns a float division result (step 3), while // returns the floor (integer part) of the division (step 4).
Why does adding an int and a float result in a float?
Python converts int to float in mixed operations to avoid losing decimal info, so 5 + 0.5 becomes 5.5 (step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of variable 'c' after step 3?
A2
B2.5
C3
D5
💡 Hint
Check the 'Result' column in row for step 3 in execution_table.
At which step does the floor division operator (//) get used?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look for the action mentioning '//' in the execution_table.
If variable 'a' was changed to 6, what would be the new value of 'd' after step 4?
A2.5
B2
C3
D4
💡 Hint
Floor division truncates the decimal, so 6 // 2 equals 3 (see step 4 logic).
Concept Snapshot
Numeric values in Python:
- int: whole numbers (e.g., 5)
- float: decimal numbers (e.g., 2.5)
- / always returns float
- // returns floor int
- int + float = float
Use these rules to predict results.
Full Transcript
This lesson shows how Python handles numbers. We assign integers and floats, then do math operations. Division with / always gives a float result, even if both numbers are integers. Floor division // gives the integer part only. Adding an integer and a float results in a float. Variables change step by step as operations happen, and the type of result depends on the operation used.