Course outline · 0% complete

0/32 lessons0%

Course overview →

Values and Types

lesson 1-1 · ~9 min · 1/32

Every piece of data is a value

Every program, from a calculator to a chat app, is instructions working on data. Python sorts data into types because each type supports different operations: you can multiply two numbers, but multiplying two names makes no sense. Knowing a value's type tells you, and Python, exactly what you are allowed to do with it, and most beginner crashes are type mix-ups, so this pays off from day one.

A value is a single piece of data a program works with: the number 42, the text "hello", the answer True. Every value in Python has a type. The four types you will use constantly:

TypeNameExamples
intwhole number42, -7, 0
floatdecimal number3.5, -0.25
strtext (a string of characters)"hello", "42"
booltruth valueTrue, False

Text always sits inside quotes. That is how Python tells the text "42" apart from the number 42.

Your first two functions

print() and type() are functions: named instructions built into Python. You run a function by writing its name followed by parentheses, and the parentheses hold the value you want the instruction to work on. That placement is the actual rule of the language: Python reads print(42) as "run the instruction named print on the value 42". print() shows a value on the screen, and type() reports a value's type.

Code exercise · python

Run this program. `print()` shows a value on the screen, one line per call. Notice how `type()` reports each value's type.

Quiz

In `type(42)`, what job do the parentheses do?

Quiz

Which of these values has type str?

Code exercise · python

Your turn. Print the text `Python has 4 basic types` on one line. Then print the type of `2.5`, and then the type of `False`.