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

Python Data Types

The document provides an overview of Python data types, which categorize data items into various classes such as Numeric, Sequence, Mapping, Boolean, and Set types. It includes examples of each data type, demonstrating their usage and characteristics through code snippets. Additionally, it highlights how variables in Python are instances of these data type classes.

Uploaded by

ashuthakur6106
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 views3 pages

Python Data Types

The document provides an overview of Python data types, which categorize data items into various classes such as Numeric, Sequence, Mapping, Boolean, and Set types. It includes examples of each data type, demonstrating their usage and characteristics through code snippets. Additionally, it highlights how variables in Python are instances of these data type classes.

Uploaded by

ashuthakur6106
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/ 3

5/5/25, 5:03 PM Python Data Types

Python Data types are the classification or categorization of


data items.

It represents the kind of value that tells what operations can


be performed on a particular data.

Since everything is an object in Python programming,

Python data types are classes and variables are instances


(objects) of these classes.

The following are the standard or built-in data types in


Python:
Numeric – int, float, complex
Sequence Type – string, list, tuple
Mapping Type – dict
Boolean – bool
Set Type – set

In [2]: a = 5
print(type(a))

b = 5.0
print(type(b))

c = 2 + 4j
print(type(c))

<class 'int'>
<class 'float'>
<class 'complex'>

In [16]: _test5 = 100


print(_test5)

100

In [18]: s = 'Welcome to the World'


print(s)

# check data type


print(type(s))

# access string with index


print(s[1])
print(s[2])
print(s[-4])

file:///C:/Users/Lenovo/Downloads/Python Data Types.html 1/3


5/5/25, 5:03 PM Python Data Types

Welcome to the World


<class 'str'>
e
l
o

In [20]: # Empty list


a = []

# list with int values


a = [1, 2, 3]
print(a)

# list with mixed int and string


b = ["Loops", "For", "Loops", 4, 5]
print(b)

[1, 2, 3]
['Loops', 'For', 'Loops', 4, 5]

In [30]: a = ["L", "For", "Loops"]


# print("Accessing element from the list")
# print(a[0])
# print(a[2])

print("Accessing element using negative indexing: ", end = ' ')


print(a[-1], end = ' ')
print(a[-3])

Accessing element using negative indexing: Loops L

In [32]: # initiate empty tuple


tup1 = ()

tup2 = ('Loops', 'For')


print("\nTuple with the use of String: ", tup2)

Tuple with the use of String: ('Loops', 'For')

In [16]: print(type(True))
print(type(False))
print(type(true))

<class 'bool'>
<class 'bool'>
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[16], line 3
1 print(type(True))
2 print(type(False))
----> 3 print(type(true))

NameError: name 'true' is not defined

In [40]: # initializing empty set


s1 = set()

s1 = set("rakesh")
print("Set with the use of String: ", s1)

file:///C:/Users/Lenovo/Downloads/Python Data Types.html 2/3


5/5/25, 5:03 PM Python Data Types

s2 = set(["s", "For", "s"])


print("Set with the use of List: ", s2)

Set with the use of String: {'r', 'e', 'a', 's', 'h', 'k'}
Set with the use of List: {'s', 'For'}

In [20]: set1 = set(["s", "For", "s"])


print(set1)

# loop through set


for i in set1:
print(i, end=" ")

# check if item exist in set


print("s" in set1)

{'s', 'For'}
s For True

In [1]: # initialize empty dictionary


d = {}

d = {1: 'apple', 2: 'mango', 3: 'grapes'}


print(d)

# creating dictionary using dict() constructor


d1 = dict({1: 'apple', 2: 'mango', 3: 'grapes'})
print(d1)

{1: 'apple', 2: 'mango', 3: 'grapes'}


{1: 'apple', 2: 'mango', 3: 'grapes'}

In [1]: # initialize empty dictionary


# d = {}

d = {1: 'apple', 2: 'mango', 3: 'grapes'}


print(d)

# creating dictionary using dict() constructor


d1 = dict({1: 'apple', 2: 'mango', 3: 'grapes'})
print(d1)

{1: 'apple', 2: 'mango', 3: 'grapes'}


{1: 'apple', 2: 'mango', 3: 'grapes'}

In [42]: d = {1: 'G', 'name': 'or', 3: 'G'}

# Accessing an element using key


print(d[3])

# Accessing a element using get


print(d.get(3))

G
G

In [ ]:

file:///C:/Users/Lenovo/Downloads/Python Data Types.html 3/3

You might also like