Python Data Types and Variables Explained With Simple Examples
Data types in Python classify the kind of value a variable can hold. Python’s built-in types include int, float, str, bool, complex, and NoneType. Python assigns the type automatically when you assign a value, so you never write the type name yourself. Understanding what are data types in Python is the first step to writing reliable code.
- Python variables are labels that point to values stored in memory, not containers with fixed types.
- Python has at least 8 built-in data types you will use regularly as a beginner.
- Dynamic typing means one variable can hold an integer now and a string five lines later.
- Identifiers follow strict naming rules, and Python reserves 35 keywords you cannot use as variable names.
- The type() and isinstance() functions let you inspect a variable’s type at any point in your code.
What Is a Variable in Python and How Do You Declare One?
A variable in Python is simply a name that refers to a value. Think of it as a sticky label you put on a box. The label is the variable name; whatever is inside the box is the value. Python stores the value in memory and your variable points to it.
How to declare a variable in Python is refreshingly simple: just write the name, an equals sign, and the value. No var, no int, no type annotation required at the basic level.
Let’s use a single running example throughout this article: a student record. Imagine you’re building a small program to store details about a student named Priya enrolled at a Delhi college.
- student_name = “Priya” stores her name as a string.
- student_age = 20 stores her age as an integer.
- student_gpa = 8.7 stores her GPA as a float.
- is_enrolled = True stores her enrollment status as a boolean.
That’s it. Four variables, four Python variable types, zero type declarations. Python reads the right side of the equals sign and decides the type for you. If you want structured guidance on where these skills lead, the online certification courses at 3.0 University cover Python from basics through to job-ready applications.
What Is an Identifier in Python?
An identifier is any name you give to a variable, function, class or module. student_name, age, and calculate_gpa are all identifiers. Python enforces a short set of rules for them.
- Identifiers can contain letters (A-Z, a-z), digits (0-9) and underscores (_).
- They must start with a letter or an underscore, never a digit.
- They are case-sensitive: Age and age are two different identifiers.
- They cannot be a reserved keyword like if, for, or class.
PEP 8, Python’s official style guide, recommends using lowercase letters with underscores for variable names: student_name rather than StudentName or studentname. Consistent naming makes your code far easier to read when you revisit it weeks later or share it with teammates.
What Are Keywords in Python?
Python currently reserves 35 keywords (as of Python 3.12, confirmed in the official Python documentation). These are words the interpreter uses for its own grammar. You cannot use them as variable names.
Common ones you will see constantly: if, else, elif, for, while, def, class, return, import, True, False, None, and, or, not, in, is. Try naming a variable class = “BCA” and Python will throw a SyntaxError immediately.
If you are curious about what a programming foundation like this leads to career-wise, the 3.0 University blog covers how Python skills connect to high-demand roles in AI, data science and cybersecurity.
How Many Data Types Are There in Python? A Full Breakdown
Python ships with a generous set of built-in types. Beginners often ask how many data types in Python are there, and the honest answer is: it depends on how you count. The core numeric and sequence types you need to know first number around eight, but Python’s type system goes much deeper once you hit collections and custom classes.
Here is a compact reference table covering the Python int float string bool and other types every beginner must know:
| Data Type | Category | Example (Student Record) | Mutable? |
|---|---|---|---|
| int | Numeric | student_age = 20 | No |
| float | Numeric | student_gpa = 8.7 | No |
| complex | Numeric | signal = 3 + 2j | No |
| str | Sequence | student_name = “Priya” | No |
| bool | Boolean | is_enrolled = True | No |
| list | Sequence | subjects = [“Maths”, “CS”] | Yes |
| tuple | Sequence | coords = (28.6, 77.2) | No |
| NoneType | Special | result = None | No |
Notice the “Mutable?” column. Mutable vs immutable in Python is a distinction that matters a lot once you start writing functions. A list is mutable: you can add or remove subjects from Priya’s subject list. A str is immutable: if you “change” a string, Python actually creates a brand-new string object in memory. This distinction matters once you start writing functions and want to avoid accidental side effects.
How to Check Data Type in Python Using type() and isinstance()
Python gives you two built-in tools to inspect types at runtime. The first is type(), which returns the exact type of any object.
- type(student_age) returns <class ‘int’>
- type(student_gpa) returns <class ‘float’>
- type(student_name) returns <class ‘str’>
The second is isinstance(), which checks whether a variable belongs to a type or any of its parent types. isinstance(student_age, int) returns True. This is more useful in real code because it handles inheritance correctly, something type() alone does not do cleanly.
A quick practical habit: when your code behaves oddly, drop a type() call on the suspect variable. Nine times out of ten you will find a string where you expected an integer, or a float where you needed an int for an index.
Python’s extensive standard library is one reason it ranked as the most popular programming language for the third consecutive year in the Stack Overflow Developer Survey 2024, with 51% of all respondents saying they use it regularly. That popularity means your Python knowledge transfers across web development, data analysis, automation and security work.
Dynamic Typing in Python: What It Means and Why It Matters
Dynamic typing means Python determines a variable’s type at runtime, not at compile time. You do not declare types up front. Python reads the value you assign and tags the object with the appropriate type internally. This is central to understanding what are data types in Python and how they behave differently from languages like Java or C++.
Back to Priya’s student record. Suppose her roll number comes in as a string from a form input: roll_number = “2024CS042”. Later in the program you reassign it: roll_number = 2024042. Python does not complain. The variable now points to an integer object instead of a string object. The type changed because the value changed.
This flexibility speeds up prototyping, which is why Python is the go-to language for data science and AI work. According to JetBrains’ State of Developer Ecosystem 2023, 59% of Python developers use it for data analysis, making it the single most common Python use case globally. According to NASSCOM’s Tech Talent Report 2024, Python is the most in-demand programming language for technology hiring across India, appearing in over 65% of data and AI job postings on major platforms.
Dynamic typing does carry a trade-off. Bugs where a variable holds the wrong type can slip through and only surface at runtime. That is why tools like type hints (introduced in PEP 484) and static checkers like mypy exist: they let you annotate types voluntarily and catch mismatches before you run the code.
Dynamic Typing vs Static Typing: A Quick Comparison
Languages like Java and C++ use static typing: you declare int age = 20; and that variable can only ever hold an integer. If you try to assign a string to it, the compiler refuses before the program even runs.
Python’s dynamic approach means less boilerplate and faster early development. The cost is that you need discipline with naming and testing to catch type errors that a static compiler would catch automatically. For students in India preparing for roles at product companies and startups, understanding this trade-off helps you read job descriptions and choose the right tool for each project.
If you are thinking about where Python fits in a broader career path, check out this guide on AI, blockchain and data science careers in India to see how foundational Python knowledge connects to high-growth roles.
The TIOBE Index for June 2025 ranked Python at number one with a rating of 23.84%, nearly double the second-placed language. That single data point explains why colleges across India, from IITs to state engineering universities, now introduce Python in the first semester.
Putting It All Together: The Student Record in One Block
Here is the complete student record example using every concept covered so far. You can copy this into any Python environment and run it right now.
- student_name = “Priya” – str, immutable
- student_age = 20 – int, immutable
- student_gpa = 8.7 – float, immutable
- is_enrolled = True – bool, immutable
- subjects = [“Maths”, “CS”, “English”] – list, mutable
- result = None – NoneType, used as a placeholder before results are known
- print(type(student_gpa)) – prints <class ‘float’>
- print(isinstance(is_enrolled, bool)) – prints True
Every line is a real, runnable Python statement. No setup beyond a standard Python 3 install. If you want structured guidance with projects and peer support, 3.0 University’s bootcamp training programs take you from these basics through to job-ready Python applications in a matter of weeks.
Once you are comfortable with data types in Python, a natural next topic is how data scales: see the Big Data Analytics notes on the 3.0 University learn hub to understand what happens when your Python programs process millions of records instead of one student’s details.
Your concrete next steps this week: open Python’s interactive shell (just type python3 in your terminal), recreate the student record above, and experiment by passing each variable to type() and isinstance(). Then deliberately break a naming rule, like starting a variable with a digit or using a keyword, and read the error message carefully. Error messages are teaching moments, not failures.
When you are ready to go further, the REACH learner community at 3.0 University connects you with peers working through the same material, so you are not learning alone.
Frequently Asked Questions
What are data types in Python?
Data types in Python classify the kind of value a variable holds. Python’s core built-in types include int (whole numbers), float (decimals), str (text), bool (True or False), complex (complex numbers), and NoneType (the absence of a value). The type determines what operations you can perform on the variable.
How do you declare a variable in Python?
You declare a variable by writing its name, an equals sign, and a value: age = 20. There is no keyword like var or int needed. Python infers the type from the value you assign. You can reassign the same variable to a completely different type later and Python will not object, because of dynamic typing.
How many data types are there in Python?
Python has around eight commonly used built-in data types for beginners: int, float, complex, str, bool, list, tuple, and NoneType. The full standard library includes many more, such as dict, set, frozenset and bytes. The exact count grows once you include all classes in Python’s standard library.
What is an identifier in Python?
An identifier is the name you give to a variable, function, class or module. It must start with a letter or underscore, can contain letters, digits and underscores, and is case-sensitive. You cannot use Python’s 35 reserved keywords as identifiers. PEP 8 recommends lowercase letters with underscores for variable names: student_name, not StudentName.
What is dynamic typing in Python?
Dynamic typing means Python assigns a type to a variable at runtime based on the value it holds, not at compile time. You do not declare the type yourself. A variable can hold an integer, then be reassigned to a string later in the same program. This speeds up development but means type errors only appear when the code actually runs, not before.
What is the difference between mutable and immutable data types in Python?
Mutable data types in Python, like list, can be changed after creation: you can add, remove or update items. Immutable types, like int, str, float, bool and tuple, cannot be changed after creation. When you appear to modify an immutable object, Python creates a new object in memory instead.
Last updated: June 2025. Reviewed by the 3University editorial team.


