Py Lecture 3
Py Lecture 3
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-:
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.
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-: