2. Data type

type() is a built-in function. Its signature is:

It returns the type of the value you pass.

Common types:

  • int — whole numbers: 10, -5, 0
  • float — decimal numbers: 3.14, 1.0
  • str — text in quotes: "hello"
  • bool — True or False
  • NoneType — the type of None, which means "no value"

Printing a type shows it as <class 'int'>, <class 'str'> and so on.

Coming from JavaScript? JS has one number type; Python separates whole numbers (int) and decimals (float). None covers JS null and undefined, and type(x) prints a class instead of returning a string like typeof.

#01

Integers

Whole numbers such as 10 are of type int. Pass the number to type() and print the result.

Print exactly:

Output
Run your code to see the output here.
#02

Floats

Numbers with a decimal point, such as 3.14, are of type float. Pass one to type() and print the result.

Print exactly:

Output
Run your code to see the output here.
#03

Strings

Text inside quotes, such as "hello", is of type str. Pass it to type() and print the result.

Print exactly:

Output
Run your code to see the output here.
#04

Booleans

True and False are of type bool. Pass one to type() and print the result.

Print exactly:

Output
Run your code to see the output here.
#05

None

None is a special value that means "no value". Its type is NoneType. Pass it to type() and print the result.

Print exactly:

Output
Run your code to see the output here.
#06

Same text, different type

42 and "42" look similar, but one is a number and the other is text. Print the type of both in a single print() call.

Print exactly:

Output
Run your code to see the output here.