0% found this document useful (0 votes)
14 views21 pages

Py Lecture 3

Uploaded by

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

Py Lecture 3

Uploaded by

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

PYTHON 3.12.

3
LEARN WITH FUN
LECTURE-3
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.
x = "Hello World"
x = 50
x = 60.5
x = 3j
x = ["Python", "for", "Beginners"]
x = ("python", "for", "beginners")
x = range(10)
x = {"name": "Suraj", "age": 24}
x = {"python", "for", "beginners"}
x = frozenset({"python", "for", "beginners"})
x = True
x = b"Python"
x = bytearray(4)
x = memoryview(bytes(6))
x = None
1. Numeric Data Types in Python-:
● Integer
● Float
● Complex Numbers like–: (-2+3j)

Example-:
a=5
print("Type of a: ", type(a))

b = 5.0
print("\nType of b: ", type(b))

c = 2 + 4j
print("\nType of c: ", type(c))
2. Sequence Data Types in Python-:
The sequence Data Type in Python is the ordered collection of similar or different Python data types.

● Python String
● Python List
● Python Tuple
● Python String-:

String1 = 'Welcome to the Hello World'


print("String with the use of Single Quotes: ")
print(String1)
String1 = "I'm a Rohan"
print("\nString with the use of Double Quotes: ")
print(String1)
print(type(String1))
String1 = '''I'm a Rohan and I live in a world of "Python"'''
print("\nString with the use of Triple Quotes: ")
print(String1)
print(type(String1))
String1 = '''Python
For
Beginners'''
print("\nCreating a multiline String: ")
print(String1)
● Accessing elements of String-:

Example-:

String1 = "PythonForBeginners"
print("Initial String: ")
print(String1)
print("\nFirst character of String is: ")
print(String1[0])
print("\nLast character of String is: ")
print(String1[-1])
● List Data Type-:
Lists are just like arrays, declared in other languages which is an ordered collection of
data. It is very flexible as the items in a list do not need to be of the same type.

Creating a List in Python-:


List = []
print("Initial blank List: ")
print(List)
List = ['PythonForBeginners']
print("\nList with the use of String: ")
print(List)
List = ["Python", "For", "Beginners"]
print("\nList containing multiple values: ")
print(List[0])
print(List[2])
List = [['Python', 'For'], ['Beginners']]
print("\nMulti-Dimensional List: ")
print(List)
● Python Access List Items-:
Example-:

List = ["Python", "For", "Beginners"]


print("Accessing element from the list")
print(List[0])
print(List[2])
print("Accessing element using negative indexing")
print(List[-1])
print(List[-3])
● Tuple Data Type-:

Just like a list, a tuple is also an ordered collection of


Python objects. The only difference between a tuple and a
list is that tuples are immutable i.e. tuples cannot be
modified after it is created. It is represented by a tuple
class.
Creating a Tuple in Python-:
Example-:
Tuple1 = ()
print("Initial empty Tuple: ")
print(Tuple1)
Tuple1 = ('Python', 'For')
print("\nTuple with the use of String: ")
print(Tuple1)
list1 = [1, 2, 4, 5, 6]
print("\nTuple using List: ")
print(tuple(list1))
Tuple1 = tuple('Python')
print("\nTuple with the use of function: ")
print(Tuple1)
Tuple1 = (0, 1, 2, 3)
Tuple2 = ('python', 'hello')
Tuple3 = (Tuple1, Tuple2)
print("\nTuple with nested tuples: ")
print(Tuple3)
Access Tuple Items-:

tuple1 = tuple([1, 2, 3, 4, 5])


print("First element of tuple")
print(tuple1[0])
print("\nLast element of tuple")
print(tuple1[-1])

print("\nThird last element of tuple")


print(tuple1[-3])
● Boolean Data Type in Python-:

Example-:
print(type(True))
print(type(False))

print(type(true))
● Set Data Type in Python-:
“A Set is an unordered collection of data types that is
iterable, mutable, and has no duplicate elements. The order
of elements in a set is undefined though it may consist of
various elements.”
Create a Set in Python-:

set1 = set()
print("Initial blank Set: ")
print(set1)
set1 = set("PythonForBeginners")
print("\nSet with the use of String: ")
print(set1)
set1 = set(["Python", "For", "Beginners"])
print("\nSet with the use of List: ")
print(set1)
set1 = set([1, 2, 'Python', 4, 'For', 6, 'Beginners'])
print("\nSet with the use of Mixed Values")
print(set1)
Access Set Items-:

set1 = set(["Python", "For", "Beginners"])


print("\nInitial set")
print(set1)
print("\nElements of set: ")
for i in set1:
print(i, end=" ")
print("Python" in set1)
● Dictionary Data Type in Python-:
A dictionary in Python is an unordered collection of data
values, used to store data values like a map.
A Dictionary holds a key: value pair. Key-value is provided in
the dictionary to make it more optimized. Each key-value pair
in a Dictionary is separated by a colon : , whereas each key is
separated by a ‘comma’.
Create a Dictionary in Python-:
Dict = {}
print("Empty Dictionary: ")
print(Dict)
Dict = {1: 'Python', 2: 'For', 3: 'Beginners'}
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
Dict = {'Name': 'Python', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ")
print(Dict)
Dict = dict({1: 'Python', 2: 'For', 3: 'Beginners'})
print("\nDictionary with the use of dict(): ")
print(Dict)
Dict = dict([(1, 'Python'), (2, 'For')])
print("\nDictionary with each item as a pair: ")
print(Dict)
Accessing Key-value in Dictionary-:

Dict = {1: 'Python', 'name': 'For', 3: 'Beginners'}


print("Accessing a element using key:")
print(Dict['name'])
print("Accessing a element using get:")
print(Dict.get(3))
THANK YOU

You might also like