Coding/Learn/python/data types
Python Beginner Course
01.Introduction to Python
02.Your First Python Program
03.Syntax & Indentation
04.Comments & Documentation
05.Variables
06.Core Data Types
07.Numbers & Arithmetic Operators
08.Text & Strings in Depth
09.Boolean Logic
10.Type Conversion & Casting
11.Interactive User Input
12.Assignment & Shorthand Operators
13.Comparison Operators
14.Logical Operators (and, or, not)
15.If Statements & Conditional Execution
16.If-Else Branching (Dual Paths)
17.If-Elif-Else (Multi-Path Decisions)
18.While Loops & Iteration
19.For Loops & Sequence Traversal
20.The range() Function
21.Lists & Mutable Sequences
22.Tuples & Immutable Data
23.Sets & Unique Collections
24.Dictionaries & Key-Value Stores
25.List Indexing & Slicing
26.Essential List Methods
27.Essential String Methods
28.Functions & Modular Code
29.Function Parameters & Arguments
30.Return Values & Data Flow
31.Exception Handling (try / except)
32.Capstone Mini-Projects
Course Certificate0%

Complete all lessons to earn

LearnCore Data Types
6 / 32 0%
Lesson 06 of 32
6 mins read

Core Data Types

PreviousNext Lesson
In Plain English

Computers are very particular about what kind of data they handle. Text is a String (str), whole numbers are Integers (int), decimals are Floats (float), and true/false states are Booleans (bool). Python figures this out automatically when you type.

The Mental Model

"Imagine your backpack. Books are strings of text, whole coins in your pocket are integers, a receipt with $4.99 is a float with decimals, and whether your zipper is open or closed is a boolean (True or False). You treat each item according to its kind."

Deep Dive: How It Works

String (str): Text wrapped in quotes ("hello", 'world'). Strings can contain letters, numbers, spaces, and punctuation.

Integer (int): Whole numbers positive, negative, or zero (42, -7, 0) without any decimal points.

Float (float): Numbers that contain a fractional part with a decimal point (3.14159, 99.95, -0.5).

Boolean (bool): Exactly two values: True or False (capitalized in Python). Used for logic, checks, and switches.

You can inspect the type of any variable or value at runtime using the built-in type() function: type(42) returns <class 'int'>.

Syntax Blueprint

name = "Zen"     # str
count = 10        # int
price = 19.99     # float
is_active = True  # bool

Python automatically assigns the correct data type based on how the value is written.

PointCore Rules to Remember

Point star
String (str): Text in quotes, like "ZenCompiler" or "Pizza".
Point star
Integer (int): Whole counting numbers, like 42, 100, or -5.
Point star
Float (float): Numbers with decimals, like 3.14 or 99.99.
Point star
Boolean (bool): True or False. The bedrock of computer decisions.

Common Beginner Traps & How to Fix Them

Mistake:Putting quotes around numbers: age = "20"

Why it happens: Wrapping numbers in quotes turns them into text. "20" + "20" produces "2020", not 40.

How to fix: Leave numbers unquoted if you plan to do math with them.

Pro Tip: Use type(variable_name) whenever you are unsure what data type a variable holds.

Live Interactive Example

Hit Run Code to see it live
Inspecting Data Types with type()
Python 3.12
1
2
3
4
5
6
7
8
9
Output Console
Click "Run Code" to view the rendered output.
How it works: The type() function reveals the underlying class that Python created for each value.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Check the data type of a variable

  • PointCreate a variable called score with the integer value 100.
  • PointUse print(type(score)) to print its data type.
1
2
3
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates