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: True or False. 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 = Usman will cause a NameError because Python thinks Usman is a variable. It should be name = "Usman".
  • Lowercase booleans: Using true instead of True will cause an error.

Lesson Progress

Practice This TopicTake QuizBuild a Python Project

Ready to practise?

Apply what you learned with a hands-on challenge.

Practise This Topic