trylineTryline homeF1 · First steps
About 4 minutes

Data types

Every value has a kind: text, whole number, decimal number, True/False, or nothing. You'll learn to tell them apart, and ask Python which kind a value is.

1. Values come in kinds

So far, every value we've used was text, inside quotes. But Python works with other kinds of values too. Let's meet them.

name = "Alex"
age = 26
height = 5.8
is_student = True
nickname = None
"Alex"Text. Python calls text a string, written str.
26A whole number. Python calls it an int, short for integer. No quotes.
5.8It has a decimal point, so it's a float.
TrueA bool: it can only be True or False. Like a switch, on or off.
NoneNone means 'nothing here yet'. Alex just doesn't have a nickname.

2. Asking Python: what kind is this?

You can ask Python what kind a value is, with type.

No quotes
print(type(26))
OUTPUT
<class 'int'>
class int. A number.
Quotes
print(type("26"))
OUTPUT
<class 'str'>
class str. Text! Because of the quotes.

So 26 and "26" look almost the same, but to Python they're completely different. Quotes always make text.

TRY IT: ASK THE TYPE OF A DIFFERENT VALUE, THEN RUN
OUTPUT
Press Run
What kind is "5.8" (with quotes)?

3. Two mistakes to watch

True with a small t
done = true
NameError: name 'true' is not defined
Python doesn't know any name called true. The real one has a capital T. Same for False and None.

Mistake two: a number in quotes. It looks like a number, but it's text. That matters soon, when we start doing maths: Python can't do maths with text.

Which line makes a bool?

4. Where it's used

Every form you fill online uses these kinds. Your name is text, your age is a whole number, the price is a decimal, and 'remember me' is a True or False switch.

Banking: name, balance, is_activeData: every column has a kindOnline forms
One more short lesson before your missionF1.6 Asking the user: input()
Next lesson
Was this page clear?