-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatatype.py
More file actions
69 lines (58 loc) · 2.54 KB
/
Copy pathDatatype.py
File metadata and controls
69 lines (58 loc) · 2.54 KB
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
# =====================================================================
# FILE: Datatype.py
# DESCRIPTION: Overview of core primitive, non-primitive, and user-defined datatypes.
#
# SYNTAX QUICK-REFERENCE:
# x: int = 10
# y: float = 3.14
# name: str = "Alice"
# is_true: bool = True
# empty: None = None
# =====================================================================
# Datatype.py
# Reference Guide: Primitive, Non-Primitive, and User-Defined Datatypes in Python
# ==========================================
# 1. WHAT IS A DATATYPE?
# ==========================================
# A datatype defines the classification of data, telling the interpreter how
# the developer intends to use the data and what operations can be performed on it.
# ==========================================
# 2. PRIMITIVE DATATYPES
# ==========================================
# Core built-in datatypes for single values.
print("--- 1. PRIMITIVE DATATYPES ---")
age: int = 30 # Integer (int)
pi: float = 3.14 # Floating point (float)
name: str = "Alice" # String (str)
is_student: bool = True # Boolean (bool)
empty_val = None # NoneType (None)
print(f"Integer age: {age} ({type(age)})")
print(f"Float pi: {pi} ({type(pi)})")
print(f"String name: {name} ({type(name)})")
print(f"Boolean student: {is_student} ({type(is_student)})")
print(f"None Value: {empty_val} ({type(empty_val)})")
print()
# ==========================================
# 3. NON-PRIMITIVE DATATYPES (Collections)
# ==========================================
# Structures that store collections of values.
print("--- 2. NON-PRIMITIVE DATATYPES ---")
user_list = [1, 2, 3] # List (ordered, mutable)
user_tuple = (1, 2, 3) # Tuple (ordered, immutable)
user_dict = {"name": "Alice", "age": 30} # Dictionary (key-value mapping)
user_set = {1, 2, 3} # Set (unordered collection of unique items)
print(f"List: {user_list} ({type(user_list)})")
print(f"Tuple: {user_tuple} ({type(user_tuple)})")
print(f"Dictionary: {user_dict} ({type(user_dict)})")
print(f"Set: {user_set} ({type(user_set)})")
print()
# ==========================================
# 4. USER-DEFINED DATATYPES (Classes)
# ==========================================
# Custom blueprints created using classes.
print("--- 3. USER-DEFINED DATATYPES ---")
class Person:
pass
person1 = Person()
print(f"Custom Object Instance: {person1} ({type(person1)})")
print()