-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-types.py
69 lines (54 loc) · 1.45 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
# Data Types in Python
# Text Type: str
x = "Hello World"
print(x)
print(type(x))
# Numeric Types: int, float, complex
x = 20
print(x)
print(type(x))
x = 20.5
print(x)
print(type(x))
x = 1j
print(x)
print(type(x))
# Sequence Types: list, tuple, range
x = ["apple", "banana", "cherry"] # List is a collection which is ordered and changeable.
print(x)
print(type(x))
x = ("apple", "banana", "cherry") # Tuple is a collection which is ordered and unchangeable.
print(x)
print(type(x))
x = range(6) # Range is a collection which is ordered and unchangeable.
print(x)
print(type(x))
# Mapping Type: dict
x = {"name" : "John", "age" : 36} # Dictionary is a collection which is unordered, changeable and indexed.
print(x)
print(type(x))
# Set Types: set, frozenset
x = {"apple", "banana", "cherry"} # Set is a collection which is unordered and unindexed.
print(x)
print(type(x))
x = frozenset({"apple", "banana", "cherry"}) # Frozen set is a collection which is unordered and unindexed.
print(x)
print(type(x))
# Boolean Type: bool
x = True
print(x)
print(type(x))
# Binary Types: bytes, bytearray, memoryview
x = b"Hello" # Bytes is a collection which is ordered and unchangeable.
print(x)
print(type(x))
x = bytearray(5) # Bytearray is a collection which is ordered and changeable.
print(x)
print(type(x))
x = memoryview(bytes(5)) # Memoryview is a collection which is ordered and changeable.
print(x)
print(type(x))
# None Type: NoneType
x = None
print(x)
print(type(x))