Core Data Types

Beginner · 17 min read · ▶ live playground · ✦ checkpoint

Python can remember 7, "Ada", True, and None, but it doesn't treat them as the same kind of thing. Core data types are Python's first value categories: whole numbers, decimal numbers, text, yes/no facts, and deliberate nothingness.

Values have kinds

A data type is the kind of value Python is holding, which tells Python what that value is meant to be. Think of a data type like the shape of a puzzle piece: the shape decides what it can connect to. A Python object is a value living in memory; a score-shaped object is not the same as a name-shaped object.

Python gives you a built-in function named type(). A function is reusable behavior you can call with parentheses; functions get their full story in lesson 7.1. For now, type(value) tells you the data type of value.

score = 18
player = "Mina"
game_started = True
winner = None
 
print(type(score))
print(type(player))
print(type(game_started))
print(type(winner))

<class 'int'>
<class 'str'>
<class 'bool'>
<class 'NoneType'>

The word class in that output means "kind of object" for now. Classes get their full story in Part III. For this lesson, read <class 'int'> as "Python sees an integer here."

Numbers: int, float, and complex

An integer is a whole number with no decimal point. Python calls that type int.

A float is Python's floating-point numeric type, commonly written here with a decimal point. Floating point is a way computers store decimal-style numbers. You use floats for values like temperatures, prices, and averages. Lesson 2.3 shows the famous floating-point surprise; today you only need to recognize the type.

A complex number is a number with a real part and an imaginary part. Python writes the imaginary part with j, so 4j is a complex value. You won't use complex numbers often unless you're doing math, science, or signals, but they are part of Python's core numeric family.

apples = 7
temperature = 21.5
signal_shift = 4j
 
print(apples)
print(type(apples))
print(temperature)
print(type(temperature))
print(signal_shift)
print(type(signal_shift))

7
<class 'int'>
21.5
<class 'float'>
4j
<class 'complex'>

Notice what this lesson is not doing yet: adding, dividing, rounding, or comparing numbers. Those are real operations, and they deserve their own lesson. Right now, you're learning to see what kind of object a name refers to.

Strings are text

A string is text data, written between quotes. Python calls the type str, short for string.

player = "Ravi"
jersey_number = "7"
mood = "ready"
 
print(player)
print(jersey_number)
print(type(jersey_number))
print(mood)

Ravi
7
<class 'str'>
ready

The jersey_number value looks like a number to you, but the quotes tell Python it is text. That distinction matters. The string "7" is a character you can print on a jersey; the integer 7 is a number you can do numeric work with in lesson 2.3.

Single quotes and double quotes both create strings:

snack = 'apples'
drink = "tea"
 
print(snack)
print(drink)
print(type(snack))

apples
tea
<class 'str'>

Pick one quote style and be consistent inside a small piece of code. The quotes are not decoration; they are the signal that says "this is text."

Try it — inspect the value shelf

Run this, then change one value at a time. Try changing score from 12 to "12", and winner from None to "Mina". Watch only the type lines.

python — playgroundlive
⌘/Ctrl + Enter to run

Booleans and None

A Boolean is a yes-or-no value. Python's Boolean values are exactly True and False, with capital first letters. Python calls their type bool.

Booleans are useful when a program needs to remember a state:

has_ticket = True
music_playing = False
snack_ready = True
 
print(has_ticket)
print(type(has_ticket))
print(music_playing)
print(type(music_playing))

True
<class 'bool'>
False
<class 'bool'>

For now, store Booleans as facts: the player has a ticket, music is not playing, the snack is ready. Boolean expressions are code pieces that produce True or False, comparisons ask questions like "is this bigger?", and truthiness is how Python treats values in yes/no checks. Those come in lesson 4.1.

None is Python's special value for "no value here yet." Its type is NoneType, the data type of the one value None.

Use None when a name should exist before the real value arrives:

winner = None
last_score = None
next_player = "Asha"
 
print(winner)
print(type(winner))
print(next_player)
print(type(next_player))

None
<class 'NoneType'>
Asha
<class 'str'>

None is not the string "None". It is not the Boolean False. It is its own object, like a reserved seat with nobody sitting in it yet: the empty seat itself tells you something.

Dynamic typing: names can move

Dynamic typing means Python tracks the type of the object while the program runs, and a name can be reassigned to an object of a different type. The name does not own a type forever. The object has the type.

That matches the sticky-label model from lesson 2.1. Reassignment moves the label:

score = 10
print(score)
print(type(score))
 
score = "ten"
print(score)
print(type(score))

10
<class 'int'>
ten
<class 'str'>

Python did not turn the integer 10 into text. It moved the name score from an int object to a str object. This flexibility is convenient, especially while exploring in the REPL, but it can confuse readers. If a name starts as a score, keep it meaning "score" unless you have a very good reason.

Checkpoint

Answer all three to mark this lesson complete

Next, numbers stop sitting still. You'll make integers and floats do real work: division, remainders, powers, and the floating-point result that surprises almost every beginner.

+50 XP on completion