#  Why Python Turns Everything You Type Into a String 

Every example I've written so far has used values I hardcoded myself: `print("Hello World")`, `a = 7`, that sort of thing. That works for learning syntax, but it's not how real software behaves. A calendar app doesn't need anything from you beyond opening it. YouTube, on the other hand, is nothing without you typing something into that search bar.

> **Term check: static vs dynamic application** A static application (like a clock or calendar) doesn't need any input from the user to function, it just displays something. A dynamic application (like YouTube or Facebook) depends on input from the user to do anything useful. Almost everything built today falls into the second category, which is exactly why taking input properly matters.

This post covers how Python actually takes input from a user while a program is running, and a surprising catch that comes with it that I had to work through before it made sense.

Quick aside: for this section, the course switched over to Jupyter Notebook instead of Google Colab, run locally through Anaconda's prompt (`cd` into your project folder, then run `jupyter notebook`). It's the same cell-by-cell way of working as Colab, just running on your own machine instead of Google's servers. Functionally, everything below works the same regardless of which one you use.

## Meet `input()`

Taking input from a user is one function: `input()`.

```python
name = input()
print(name)
```

Run this, type something, hit enter, and whatever you typed gets stored in `name` and printed back. Nothing fancy yet, but there's a small usability problem: as written, the user just sees a blank box with no idea what they're supposed to type. `input()` fixes that by accepting a message to display as a prompt:

```python
name = input("Enter your name: ")
print(name)
```

Now the person typing actually knows what's expected of them, the same way a signup form tells you which field is which instead of leaving you guessing.

![](https://cdn.hashnode.com/uploads/covers/65190f55c8ba679c8f0bec8b/dfebddac-c846-4562-ae8b-05c26a8196a9.png align="center")

## The catch: it's always a string

Here's the part that tripped me up. Type a number into `input()`, and you'd expect to get a number back. You don't.

```python
age = input("Enter your age: ")
print(type(age))  # <class 'str'>, even if you typed 25
```

Doesn't matter if you type a whole number, a decimal, or plain text, `input()` converts all of it to a string by default. This isn't a bug, it's a deliberate design choice. Since `input()` has no way of knowing in advance whether the user is about to type a name, an age, or something else entirely, storing everything as a string is the one format that never breaks, since a string can hold any of those safely. If you actually need it as a number, that's on you to convert afterward.

## Type conversion, two ways

This is where type conversion comes in, and Python actually handles it in two different situations.

> **Term check: implicit type conversion** Conversion that Python does automatically, without you asking for it. It happens when combining compatible types, and Python decides on a sensible result type for you.

```python
print(5 + 5.5)         # 10.5
print(type(5))         # <class 'int'>
print(type(5.5))       # <class 'float'>
print(type(5 + 5.5))   # <class 'float'>
```

Adding an integer and a float doesn't error out. Python quietly upgrades the result to a float, since that's the only sensible way to represent the answer without losing the decimal part. You didn't ask for that conversion, Python just did it.

> **Term check: explicit type conversion** Conversion you trigger yourself, using functions like `int()`, `float()`, or `str()`, because Python can't or won't guess what you meant.

```python
print(4 + "4")
# TypeError: unsupported operand type(s) for +: 'int' and 'str'
```

This one doesn't get an implicit pass. Adding a number to a string isn't something Python is willing to guess about, so it just errors out. Converting the string yourself fixes it:

```python
print(4 + int("4"))  # 8
```

The same functions work in the direction you'd expect for values coming out of `input()`:

```python
num = input("Enter a number: ")   # this is a string, e.g. "34"
num = int(num)
print(type(num))  # <class 'int'>

num = float(num)
print(type(num))  # <class 'float'>
```

**One restriction worth knowing:** complex numbers refuse to convert to `int` or `float`.

```python
value = 4 + 6j
print(int(value))
# TypeError: can't convert complex to int
```

This makes sense once you think about it: a complex number has two separate parts (real and imaginary), so there's no single obvious number to shrink it down to. Python would rather error out than guess wrong.

## Putting it together: a tiny two-number calculator

To actually use both of these ideas at once, here's a small addition calculator, taking two numbers from the user and adding them.

```python
n1 = input("Enter the first number: ")
n2 = input("Enter the second number: ")

# both n1 and n2 are strings right now, so convert them first
n1 = float(n1)
n2 = float(n2)

result = n1 + n2
print(result)
```

Type `2` and `3`, and you get `5.0`. Type `2.3` and `3.4`, and you get `5.7` (with the usual floating-point rounding noise Python sometimes tacks on). Converting to `float` instead of `int` was a deliberate choice here, since it lets the calculator handle decimal input too, not just whole numbers.

## Common mistakes I'd flag here

*   Assuming `input()` gives you back the type you expect. It's always a string, no matter what the user types.
    
*   Trying to do math directly on the result of `input()` without converting it first, which throws a `TypeError` the moment you add a string to a number.
    
*   Expecting implicit conversion to bail you out everywhere. It only kicks in for compatible types like int and float, not for combining numbers and plain text, and not for complex numbers at all.
    
*   Forgetting to give `input()` a prompt message. A blank input box is a small thing, but it makes your program confusing to actually use.
    

## Quick recap

*   Dynamic applications need user input to function, unlike static ones, and Python's `input()` function is how you collect it.
    
*   `input()` always returns a string, regardless of what the user actually types.
    
*   Implicit type conversion happens automatically for compatible types (like int plus float). Explicit type conversion, using `int()`, `float()`, or similar, is something you trigger yourself when Python won't guess for you.
    
*   Complex numbers can't be converted to `int` or `float`, since there's no single number that represents both their real and imaginary parts.
    
*   Combining `input()` with `float()` conversion is enough to build something genuinely useful, like a simple calculator.
    

## What's next

Based on the course outline, conditional statements are up next, which should be the first time I actually get to make a program branch based on a value instead of just running top to bottom.
