+91 81900 98289

Python Data Types

This Python Data Types lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

Every value has a type. Text is str, whole numbers are int, decimals are float, and yes/no values are bool.

type() tells you the type. A list, tuple, set, and dict hold more than one value, each with different rules.

Example 1: Start here

Knowing the type explains why \"3\" + 1 fails and 3 + 1 works.

print(type("Chennai")) # type() shows what kind of value this is print(type(24)) # type() shows what kind of value this is print(type(3.5)) # type() shows what kind of value this is print(type(False)) # type() shows what kind of value this is

Example 2: Show each type

type tells you what kind of value you have.

print(type("Chennai")) # type() shows what kind of value this is print(type(24)) # type() shows what kind of value this is print(type(True)) # type() shows what kind of value this is

Example 3: A list is its own type

Square brackets build a list.

print(type([1, 2, 3])) # type() shows what kind of value this is

Example 4: A dictionary is its own type

Curly braces with keys and values build a dictionary.

print(type({"city": "Chennai"})) # type() shows what kind of value this is
Knowing the type explains why \"3\" + 1 fails and 3 + 1 works.
Call Now 81900 98289