Ugenz Academy/Tutorial

Datatypes

5 min read988 words

Reading progress

Keep learning

Data Types in Python

A data type tells Python what kind of value a variable contains.

For example:

name = "Ram" age = 20 price = 99.5 is_student = True

Here, Python automatically identifies the type of each value.

1. Main Data Types in Python

Python has several built-in data types:

Data TypeUsed ForExample
intWhole numbers20
floatDecimal numbers20.5
complexComplex numbers2 + 3j
strText"Hello"
boolTrue/FalseTrue
listOrdered collection[10, 20, 30]
tupleOrdered, unchangeable collection(10, 20, 30)
setUnique values{10, 20, 30}
dictKey-value data{"name": "Ram"}
NoneTypeNo valueNone

2. Integer - int

Integers are whole numbers without decimal points.

age = 20 marks = 85 year = 2026

Check the type:

print(type(age))

Output:

<class 'int'>

Negative numbers are also integers:

temperature = -5

3. Float — float

A float represents a number with a decimal point.

price = 99.50 height = 5.8 percentage = 85.5

Example:

price = 99.50 print(type(price))

Output:

<class 'float'>

4. Complex — complex

Complex numbers contain a real part and an imaginary part.

number = 2 + 3j print(number) print(type(number))

Output:

(2+3j) <class 'complex'>

The j represents the imaginary part in Python.

5. String — str

A string is used to store text.

Strings can be written using:

name = "Ram" city = 'Janakpur'

You can also use triple quotes for multiple lines:

message = """Hello Welcome to Python"""

Example:

name = "Ram" print(name) print(type(name))

Output:

Ram <class 'str'>

6. Boolean — bool

Boolean values represent True or False.

Python has only two Boolean values:

True False

Example:

is_student = True is_teacher = False

Check:

print(type(is_student))

Output:

<class 'bool'>

Booleans are commonly used with conditions:

age = 20 print(age >= 18)

Output:

True

7. List — list

A list stores multiple values in a single variable.

fruits = ["Apple", "Banana", "Mango"]

Lists are:

  • Ordered
  • Changeable
  • Allow duplicate values

Example:

numbers = [10, 20, 30, 40] print(numbers)

You can change a list:

numbers[0] = 100 print(numbers)

Output:

[100, 20, 30, 40]

8. Tuple — tuple

A tuple is similar to a list, but it cannot be changed after creation.

numbers = (10, 20, 30)

Example:

colors = ("Red", "Green", "Blue") print(colors) print(type(colors))

Output:

('Red', 'Green', 'Blue') <class 'tuple'>

Tuples are useful when the data should remain unchanged.

9. Set - set

A set stores unique values.

numbers = {10, 20, 30}

Duplicate values are automatically removed:

numbers = {10, 20, 20, 30, 30} print(numbers)

Output:

{10, 20, 30}

Sets are useful when you need unique items.

10. Dictionary — dict

A dictionary stores data as key-value pairs.

student = { "name": "Ram", "age": 20, "marks": 85 }

Here:

name → Ram age → 20 marks → 85

Access a value:

print(student["name"])

Output:

Ram

Dictionaries are very commonly used when working with structured data.

11. NoneType — None

None represents the absence of a value.

result = None print(result) print(type(result))

Output:

None <class 'NoneType'>

It is commonly used when a value has not been assigned yet.

12. Checking Data Type

Python provides the type() function.

name = "Ram" age = 20 height = 5.8 student = True print(type(name)) print(type(age)) print(type(height)) print(type(student))

Output:

<class 'str'> <class 'int'> <class 'float'> <class 'bool'>

13. Type Conversion

Sometimes we need to convert one data type into another.

String to Integer

age = "20" age = int(age) print(age) print(type(age))

Integer to String

age = 20 age = str(age) print(type(age))

Integer to Float

number = 10 number = float(number) print(number)

Output:

10.0

14. Important Example with input()

Remember that input() returns a string.

age = input("Enter your age: ") print(type(age))

Even if you enter:

20

the type will be:

<class 'str'>

To get an integer:

age = int(input("Enter your age: ")) print(type(age))

Now the type is:

<class 'int'>

15. Mutable vs Immutable Data Types

This is an important concept.

Mutable

The value can be changed after creation.

Examples:

list set dict

Immutable

The value cannot be changed after creation.

Examples:

int float complex str bool tuple

For example, a list can be changed:

numbers = [10, 20, 30] numbers[0] = 100 print(numbers)

But you cannot change an individual element of a tuple:

numbers = (10, 20, 30) # numbers[0] = 100 ❌

Quick Summary

int → 10 float → 10.5 complex → 2 + 3j str → "Hello" bool → True / False list → [10, 20, 30] tuple → (10, 20, 30) set → {10, 20, 30} dict → {"name": "Ram"} NoneType → None

Simple way to remember

Basic data:

int → whole number float → decimal str → text bool → True/False

Collection data:

list → changeable collection tuple → unchangeable collection set → unique collection dict → key-value collection

The most important beginner data types to learn first are int, float, str, bool, list, tuple, set, and dict.

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy