-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data_Types.py
143 lines (104 loc) · 2.22 KB
/
Data_Types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""
In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
"""
a = "Hello World" # str
b = 20 #int
c = 20.5 #float
d = 1j #complex
e = ["apple", "banana", "cherry"] #list
f = ("apple", "banana", "cherry") #tuple
g = range(6) #range
h = {"name" : "John", "age" : 36} #dict
i = {"apple", "banana", "cherry"} #set
j = frozenset({"apple", "banana", "cherry"}) #frozenset
k = True #bool
l = "Hello" #bytes
m = bytearray(5) #bytearray
n = memoryview(bytes(5)) #memoryview
o = None #NoneType
print(a)
print(type(a))
print(b)
print(type(b))
print(c)
print(type(c))
print(d)
print(type(d))
print(e)
print(type(e))
print(f)
print(type(f))
print(g)
print(type(g))
print(h)
print(type(h))
print(i)
print(type(i))
print(j)
print(type(j))
print(k)
print(type(k))
print(l)
print(type(l))
print(m)
print(type(m))
print(n)
print(type(n))
print(o)
print(type(o))
# Setting the Specific Data Type
# If you want to specify the data type, you can use the following constructor functions:
# Example
p = str("Hello World") # str
q = int(20) # int
r = float(20.5) # float
s = complex(1j) # complex
t = list(("apple", "banana", "cherry")) # list
u = tuple(("apple", "banana", "cherry")) # tuple
v = range(6) # range
w = dict(name="John", age=36) # dict
x = set(("apple", "banana", "cherry")) # set
y = frozenset(("apple", "banana", "cherry")) # frozenset
z = bool(5) # bool
abc = bytes(5) # bytes
pqr = bytearray(5) # bytearray
xyz = memoryview(bytes(5)) # memoryview
# Print
print(p)
print(type(p))
print(q)
print(type(q))
print(r)
print(type(r))
print(s)
print(type(s))
print(t)
print(type(t))
print(u)
print(type(u))
print(v)
print(type(v))
print(w)
print(type(w))
print(x)
print(type(x))
print(y)
print(type(y))
print(z)
print(type(z))
print(abc)
print(type(abc))
print(pqr)
print(type(pqr))
print(xyz)
print(type(xyz))