← Python from Scratch
Lesson 8 of 78 · 10 XP
What is a data type?
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
Every value in Python has a type, and the type decides what you can do with that value. type() tells you the type:
type(5) # <class 'int'> — a whole number
type(2.5) # <class 'float'> — a fractional number
type("text") # <class 'str'> — a string
type(True) # <class 'bool'> — a boolean
type([1, 2]) # <class 'list'> — a list
type(None) # <class 'NoneType'>
Types matter because the same operation behaves differently:
print(2 + 3) # 5
print("2" + "3") # 23 — strings are joined
print(2 + "3") # TypeError: you can't add a number and a string
You can get just the name of a type like this: type(5).__name__ → 'int'.
Task. Write a function kind(x) that returns the name of the value's type as a string: kind(5) → 'int', kind("a") → 'str'.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.