Data types
Every value has a type. The four basic types:
stris text:"Sam"intis a whole number:30floatis a number with a decimal point:9.99boolisTrueorFalse(capital letters, no quotes)
type(x) tells you which type a value is. Watch the coloured type badges in the Visualizer.
print(type(42)) # <class 'int'>
See it run
count = 3 price = 3.0 label = "3" ready = count > 2 print(type(label), type(ready))
Three values that all look like "3" but are different types. Watch the values in the Variables box.
Practice data types
Exercise 1
Create name = "Sam", age = 30, price = 9.99 and is_member = True. Then print type(price).
Exercise 2
Describe a delivery: parcel_id is text "007", count is integer 7, weight is float 7.0, and fragile is boolean False. Print type(parcel_id).
Exercise 3
Fix the sensor record in the code editor below: room must be text "12", reading float 18.0, and online boolean False. Store type(reading) in reading_type, then print it.
Free lesson: use the editor to practice it.
Practice
Loading Python…Loading exercise content…
Visualizer Watch your code run line by line
Run your code, then choose Play to follow its execution.
Memory · names → values
Variables appear here as Python creates them.
Output & plots