0% found this document useful (0 votes)
2 views

Basic Data Types in Python

The document outlines the basic data types in Python, including numeric types (int, float, complex), boolean (bool), text (str), sequence types (list, tuple, range), set types (set, frozenset), mapping type (dict), and None type. It also describes the use of the type() function to check the data type of a variable or value, providing examples for each type. The syntax for the type() function is presented along with sample outputs.

Uploaded by

galandedikasha03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Basic Data Types in Python

The document outlines the basic data types in Python, including numeric types (int, float, complex), boolean (bool), text (str), sequence types (list, tuple, range), set types (set, frozenset), mapping type (dict), and None type. It also describes the use of the type() function to check the data type of a variable or value, providing examples for each type. The syntax for the type() function is presented along with sample outputs.

Uploaded by

galandedikasha03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic Data Types in Python

1. Numeric Types

o int – Integer (e.g., 5, -10, 1000)

o float – Floating point number (e.g., 3.14, -0.001)

o complex – Complex numbers (e.g., 2 + 3j)

2. Boolean Type

o bool – Boolean values: True or False

3. Text Type

o str – String (e.g., 'Hello', "Python")

4. Sequence Types

o list – Ordered, mutable collection (e.g., [1, 2, 3])

o tuple – Ordered, immutable collection (e.g., (1, 2, 3))

o range – Immutable sequence of numbers (e.g., range(5))

5. Set Types

o set – Unordered, mutable, no duplicates (e.g., {1, 2, 3})

o frozenset – Immutable version of a set

6. Mapping Type

o dict – Key-value pairs (e.g., {"name": "Alice", "age": 25})

7. None Type

o NoneType – Represents the absence of a value (just None)

Use of type() Function in Python

The type() function is used to:

• Check the data type of a variable or value.

• Get the class/type of an object.

Syntax:

type(object)

Examples:

print(type(10)) # <class 'int'>

print(type("Hello")) # <class 'str'>


print(type([1, 2, 3])) # <class 'list'>

print(type(3.14)) # <class 'float'>

You might also like