Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

String vs float


x = 3.14
y = "3.14"

print(x)
print(y)

print(x + 1.1)
print(y + 1.1)

Output:

3.14
3.14
4.24
Traceback (most recent call last):
  File "/home/gabor/work/slides/python/examples/basics/str_float.py", line 9, in <module>
    print(y + 1.1)
TypeError: can only concatenate str (not "float") to str