-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter 4 - Data Types.py
46 lines (33 loc) · 1.19 KB
/
Chapter 4 - 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
# Integer (int): Represents whole numbers.
x = 5
# Floating-point (float): Represents decimal numbers.
y = 3.14
# String (str): Represents sequences of characters.
name = "John"
# Boolean (bool): Represents the truth values True or False.
is_true = True
# List (list): An ordered collection of items.
# Items can be of different types.
numbers = [1, 2, 3, 4, 10]
names = ["Jenny", "Sam", "Alexis"]
mixed = ["Jenny", 1, 2]
list_of_lists = [["a", 1], ["b", 2]]
# Tuple (tuple): Similar to a list but immutable.
my_tuple = (1, "apple", 3.14)
# Set (set): An unordered collection of unique items.
my_set = {1, 2, 3}
# Dictionary (dict): Stores key-value pairs.
# Keys are unique and immutable.
my_dict = {"name": "John", "age": 30}
# NoneType (None): Represents the absence of a value.
result = None
# Bytes (bytes): Represents a sequence of bytes (immutable).
my_bytes = b"hello"
# Bytearray (bytearray): Similar to bytes but mutable.
my_bytearray = bytearray(b"hello")
# Complex (complex): Represents complex numbers.
z = 3 + 2j
# Range (range): Represents an immutable sequence of numbers.
my_range = range(0, 5)
# FrozenSet (frozenset): Similar to a set but immutable.
my_frozenset = frozenset({1, 2, 3})