Variables can store different types of data. The three basic data types in Python are:
| Data Type | Python Name | Description | Examples |
|---|---|---|---|
| Integer | int | Whole numbers | 5, 10, -3, 0 |
| Float | float | Decimal numbers | 1.5, 3.14, -0.5 |
| String | str | Text (characters) | "hello", 'Python', "42" |
| Boolean | bool | True or False | True, False |
You can check the type of any value or variable using the type() function:
>>> type(42)
<class 'int'>
>>> type(3.14)
<class 'float'>
>>> type("hello")
<class 'str'>
>>> type(True)
<class 'bool'>
A number written inside quotes is a string, not a number:
>>> type(42)
<class 'int'>
>>> type("42")
<class 'str'>
42 and "42" look similar but are completely different types. You can do arithmetic with the integer 42, but not with the string "42".
For each value below, decide whether it is an int, float, str, or bool.
"Hello World"str — it is text enclosed in quotes.
3.14float — it is a decimal number.
100int — it is a whole number.
"250"str — even though it looks like a number, the quotes make it a string.
Truebool — it is a Boolean value.
7.0float — any number with a decimal point is a float, even if the decimal part is zero.