0% found this document useful (0 votes)
3 views4 pages

pdf1

The document provides detailed examples of Python's built-in data types, including numeric types (integers, floats, complex numbers), text types (strings), sequence types (lists, tuples, ranges), mapping types (dictionaries), set types (sets, frozensets), boolean types, binary types (bytes, bytearrays, memory views), and the None type. Each data type is accompanied by a code example demonstrating its declaration and usage. This comprehensive overview serves as a reference for understanding and utilizing Python's data types.

Uploaded by

tony x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

pdf1

The document provides detailed examples of Python's built-in data types, including numeric types (integers, floats, complex numbers), text types (strings), sequence types (lists, tuples, ranges), mapping types (dictionaries), set types (sets, frozensets), boolean types, binary types (bytes, bytearrays, memory views), and the None type. Each data type is accompanied by a code example demonstrating its declaration and usage. This comprehensive overview serves as a reference for understanding and utilizing Python's data types.

Uploaded by

tony x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

give example for the above topic in details

Here are detailed examples for each of the Python data types:

1. Numeric Types

a. Integers (int)
Integers are whole numbers, either positive, negative, or zero.

# Example of integer
x = 10
print(type(x)) # Output: <class 'int'>

b. Floating-point Numbers (float)


Floats are numbers with decimal points.

# Example of float
y = 10.5
print(type(y)) # Output: <class 'float'>

c. Complex Numbers (complex)


Complex numbers have a real and an imaginary part.

# Example of complex number


z = 3 + 4j
print(type(z)) # Output: <class 'complex'>

2. Text Type

a. Strings (str)
Strings are sequences of characters enclosed in quotes.

# Example of string
name = "John Doe"
print(type(name)) # Output: <class 'str'>
3. Sequence Types

a. Lists (list)
Lists are ordered collections of items enclosed in square brackets.

# Example of list
fruits = ["apple", "banana", "cherry"]
print(type(fruits)) # Output: <class 'list'>

b. Tuples (tuple)
Tuples are ordered, immutable collections enclosed in parentheses.

# Example of tuple
colors = ("red", "green", "blue")
print(type(colors)) # Output: <class 'tuple'>

c. Ranges (range)
Ranges are sequences of numbers.

# Example of range
numbers = range(1, 6)
print(type(numbers)) # Output: <class 'range'>

4. Mapping Type

a. Dictionaries (dict)
Dictionaries are unordered collections of key-value pairs enclosed in curly brackets.

# Example of dictionary
person = {"name": "Jane", "age": 30}
print(type(person)) # Output: <class 'dict'>

5. Set Types

a. Sets (set)
Sets are unordered collections of unique items enclosed in curly brackets.

# Example of set
unique_fruits = {"apple", "banana", "cherry"}
print(type(unique_fruits)) # Output: <class 'set'>
b. Frozen Sets (frozenset)
Frozen sets are immutable sets.

# Example of frozenset
immutable_fruits = frozenset({"apple", "banana", "cherry"})
print(type(immutable_fruits)) # Output: <class 'frozenset'>

6. Boolean Type

a. Boolean (bool)
Booleans are logical values that can be either True or False.

# Example of boolean
is_admin = True
print(type(is_admin)) # Output: <class 'bool'>

7. Binary Types

a. Bytes (bytes)
Bytes are sequences of integers in the range 0 <= x < 256.

# Example of bytes
data = b"Hello"
print(type(data)) # Output: <class 'bytes'>

b. Byte Arrays (bytearray)


Byte arrays are mutable sequences of integers in the range 0 <= x < 256.

# Example of bytearray
mutable_data = bytearray(b"Hello")
print(type(mutable_data)) # Output: <class 'bytearray'>

c. Memory Views (memoryview)


Memory views are views into an existing buffer.

# Example of memoryview
view = memoryview(b"Hello")
print(type(view)) # Output: <class 'memoryview'>
8. None Type

a. None (NoneType)
None is a special type with a single value, None.

# Example of None
no_value = None
print(type(no_value)) # Output: <class 'NoneType'>

These examples cover all the built-in data types in Python, demonstrating how to declare and
use them in code.

You might also like