0% found this document useful (0 votes)
6 views5 pages

Python Built-in Data Types Explained

Data Types of Python

Uploaded by

waleedbuksh007
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)
6 views5 pages

Python Built-in Data Types Explained

Data Types of Python

Uploaded by

waleedbuksh007
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

PYTHON DATA

TYPES

1
Built-in Data Types
• Every value has a datatype, and variables can hold values.
• Python has the following data types built-in by default.

2
Getting the Data Type
• You can get the data type of any object by using the type()
function:
• Print the data type of the variable x:
x = 5
print(type(x))

3
Setting the Data Type
• In Python, the data type is set when you assign a value to a
Example Data Type
variable:
x = "Hello World" str

x = 20 int

x = 20.5 float

x = 1j complex

x = ["apple", "banana", "cherry"] list

x = ("apple", "banana", "cherry") tuple

x = range(6) range

x = {"name" : “Ali", "age" : 36} dict

x = {"apple", "banana", "cherry"} set

x = frozenset({"apple", "banana", frozenset


"cherry"})
x = True bool

x = b"Hello" bytes

x = bytearray(5) bytearray

x = memoryview(bytes(5)) memoryview

x = None NoneType
4
Examples
x='Hello World!' x = ("apple", "banana", "cherry") x = True

print(type(x)) print(type(x)) print(type(x))

x = 20 x = range(6) x = b"Hello"

print(type(x)) print(type(x)) print(type(x))

x = 20.5 x = {"name" : "Ali", "age" : 36} x = bytearray(5)

print(type(x)) print(type(x)) print(type(x))

x = 1j x = {"apple", "banana", "cherry"} x = memoryview(bytes(5))

print(type(x)) print(type(x)) print(type(x))

x = ["apple", "banana", "cherry"] x = frozenset({"apple", "banana", x = None


"cherry"})
print(type(x)) print(type(x))
print(type(x))

You might also like