Lesson 6 of 4015%
(Progress persistence is disabled until Phase 9)
Python
Beginner
Data Types
Explore the built-in data types Python provides.
Data Types
What You’ll Learn
Data types define the kind of value a variable holds. You’ll learn the most common built-in data types in Python.
Built-in Data Types
Python has the following data types built-in by default:
1. Numeric Types
- int: Whole numbers.
- float: Numbers with a decimal point.
age = 25 # int
price = 19.99 # float
2. Text Type
- str: Strings are sequences of characters, wrapped in quotes.
name = "BrowserCode" # str
3. Boolean Type
- bool: Represents one of two values:
TrueorFalse. Note the capital letters!
is_learning = True # bool
is_done = False # bool
4. Sequence Types
- list: Ordered, mutable sequence of items.
- tuple: Ordered, immutable sequence of items.
fruits = ["apple", "banana", "cherry"] # list
coordinates = (10, 20) # tuple
Getting the Data Type
You can get the data type of any object by using the type() function.
x = 5
print(type(x))
y = "Hello"
print(type(y))
Expected Output:
<class 'int'>
<class 'str'>
Common Mistakes
- Forgetting quotes around strings:
name = Usmanwill cause aNameErrorbecause Python thinksUsmanis a variable. It should bename = "Usman". - Lowercase booleans: Using
trueinstead ofTruewill cause an error.