Python Data types: Text(str), Numeric(int, float, complex), Boolean(bool)

Every value in Python carries a type, str for text, int and float and complex for numbers, bool for true or false, and the type decides what the value can do.

9 min read · 11 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

The same 30, three different meanings

In your PocketMoney tracker, the number 30 could mean three different things: the whole rupees you spent (30), a precise amount with paise (30.50), or simply the answer to 'did I overspend?' (no).

Python needs to know which kind of value it is holding, because you can do very different things with each. You can take a decimal average of amounts, but 'did I overspend' can only be true or false.

That 'which kind' is the value's data type, and Python has a small set of core ones. Meet them and you can read almost any Python program.

Theory

Types are the shape of the container

Think of values as liquids and types as the containers they arrive in: a measuring jug for exact decimals, a tally counter for whole counts, a name tag for text, a simple yes/no switch. You would not measure rainfall with a light switch. In Python the type of a value decides what operations make sense, which is why Python always keeps track of it for you.

Theory

The core types

Python's everyday built-in types:

  • str (text): anything in quotes, like "samosa".
  • int (whole numbers): 30, -5, 2026. No decimal point.
  • float (decimals): 30.5, 0.0, 3.14. Has a decimal point.
  • complex: numbers with an imaginary part, written 2 + 3j (Python uses j, not i).
  • bool (truth): exactly two values, True and False.

The function type(value) tells you which one you are holding, your main tool for checking.

At a glance

Five core types. str, int, float, and bool are the daily four; complex is specialised.

TypeExample valueUsed in PocketMoney for
str"samosa"The item name in an entry
int30Whole rupees spent, a day counter
float30.50An exact amount with paise
complex2 + 3jRare in accounts; used in engineering maths
boolTrueThe answer to 'has the budget been crossed?'

Practical

Checking types with type()

balance = 500          # int
amount = 30.50         # float
item = "samosa"        # str
over_budget = False    # bool

print(type(balance))     # <class 'int'>
print(type(amount))      # <class 'float'>
print(type(item))        # <class 'str'>
print(type(over_budget)) # <class 'bool'>

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Think first

int or float?

Before tapping: what is the type of 10 and what is the type of 10.0? Are they the same?

Show the answer

10 is an int and 10.0 is a float: not the same type, even though they are numerically equal. The decimal point is the whole story: it marks a value as a float. This matters in exams, type(10) is int, type(10.0) is float, and dividing with / in Python always gives a float (so 10 / 2 is 5.0, not 5).

Theory

The surprise about bool

bool is secretly a kind of int. In Python, True behaves as 1 and False behaves as 0.

That is not a trick you should rely on for clarity, but it explains real behaviour: True + True is 2, and True == 1 is True.

Why does this matter? Because a comparison like balance < 100 does not produce vague 'yes/no' text, it produces a real bool value you can store, print, or even count. This is the basis of every if decision you will write next unit.

Quiz

In Python, what does the expression `True == 1` evaluate to?

  1. True, because bool is a subtype of int where True equals 1
  2. False, because a boolean can never equal a number
  3. It raises a TypeError for comparing different types
  4. None, because the comparison is undefined
Show the answer

True, because bool is a subtype of int where True equals 1

In Python, bool is built on top of int: True is 1 and False is 0, so True == 1 is True (and False == 0 is True). Python happily compares them because they are the same underlying kind. This is a favourite exam catch: it does not raise an error and it does not return None.

Watch out

The quotes make it text

The single biggest beginner mistake: "30" (in quotes) is a str, not a number. It looks like 30 but you cannot do arithmetic on it, "30" + 5 is a TypeError, and "30" + "30" gives "3030", not 60. If a value came from user input or a text file, it is almost always a str until you convert it. That conversion is the very next topic (type casting).

Theory

One big change from C

In BCA104 you declared the type first (int marks;) and it was fixed forever. Python is dynamically typed: you never declare a type, the value you assign decides it, and type() reveals it. A name can even hold an int now and a str later. Freedom, but also responsibility: since Python will not warn you at declaration time, checking types with type() while debugging is a habit worth keeping.

Summary

Key takeaways

  • Every Python value has a type; type(value) reveals it.
  • str is text in quotes; int is whole numbers; float has a decimal point; complex uses j for the imaginary part.
  • bool has two values, True and False, and is a subtype of int (True == 1, False == 0).
  • 10 (int) and 10.0 (float) are equal in value but different in type; / always yields a float.
  • "30" in quotes is a str, not a number: arithmetic on it fails or concatenates.
  • Memory hook: quotes mean text, a dot means float, no dot means int, and True is just a dressed-up 1.

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Python Fundamentals

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Python Data types: Text(str), Numeric(int, float, complex), Boolean(bool) · Programming Skills · Gri-Learn