| Statement | Output |
|---|---|
| print("Hello") | Hello |
| print(10*2.5) | 25.0 |
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The table shows Python's automatic type conversion: string concatenation in the first statement and integer-to-float promotion in the second, producing Hello and 25.0.
Understanding Implicit Type Conversion in Python
Python is a dynamically typed language that performs automatic type conversion (also called implicit type conversion or type coercion) when operations involve compatible types. The two statements in the table demonstrate this behavior in different contexts.
Statement 1: print("Hello")
This is straightforward string output. The print() function accepts any object, converts it to its string representation, and writes it to standard output.
- Input type:
str(string literal"Hello") - Operation: Direct output, no conversion needed
- Output:
Hello
No type conversion occurs here because the argument is already a string.
Statement 2: print(10*2.5)
This statement involves arithmetic between an integer and a float, which triggers Python's implicit type promotion rules.
Why this conversion happens:
When Python encounters an operation between different numeric types, it follows a hierarchy to prevent data loss:
The narrower type is promoted to the wider type. Here:
10is anint2.5is afloat- Python converts
10to10.0(float) - The multiplication
10.0 * 2.5is performed in floating-point arithmetic - Result:
25.0(afloat, not25)
Step-by-step evaluation:
| Step | Expression | Type | Value |
|---|---|---|---|
| 1 | 10 | int | 10 |
| 2 | 2.5 | float | 2.5 |
| 3 | 10 → 10.0 | float | 10.0 |
| 4 | 10.0 * 2.5 | float | 25.0 |
| 5 | print(25.0) | output | 25.0 |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.