-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path080-Create-Dictionary.py
More file actions
102 lines (86 loc) · 3.12 KB
/
Copy path080-Create-Dictionary.py
File metadata and controls
102 lines (86 loc) · 3.12 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
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
"""
===============================================================================
File Name : 80-Create-Dictionary.py
Description : Create a Dictionary in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
A dictionary is a built-in collection data type used to store data as
key-value pairs. Dictionaries are mutable, unordered, and keys must be unique.
Syntax:
dictionary_name = {
key1: value1,
key2: value2
}
Example:
student = {
"id": 101,
"name": "Rahul"
}
"""
# -----------------------------------------------------------------------------
# Creating a dictionary with integer values.
# -----------------------------------------------------------------------------
numbers = {
1: 10,
2: 20,
3: 30
}
# -----------------------------------------------------------------------------
# Displaying the integer dictionary.
# -----------------------------------------------------------------------------
print("Integer Dictionary :", numbers)
# Output:
# Integer Dictionary : {1: 10, 2: 20, 3: 30}
print()
# -----------------------------------------------------------------------------
# Creating a student dictionary.
# -----------------------------------------------------------------------------
student = {
"id": 101,
"name": "Rahul",
"course": "Python",
"marks": 95
}
# -----------------------------------------------------------------------------
# Displaying the student dictionary.
# -----------------------------------------------------------------------------
print("Student Dictionary :", student)
# Output:
# Student Dictionary :
# {'id': 101, 'name': 'Rahul', 'course': 'Python', 'marks': 95}
print()
# -----------------------------------------------------------------------------
# Creating a mixed data type dictionary.
# -----------------------------------------------------------------------------
employee = {
"id": 1001,
"name": "Amit",
"salary": 45000.50,
"is_permanent": True
}
# -----------------------------------------------------------------------------
# Displaying the mixed dictionary.
# -----------------------------------------------------------------------------
print("Employee Dictionary :", employee)
# Output:
# Employee Dictionary :
# {'id': 1001, 'name': 'Amit', 'salary': 45000.5, 'is_permanent': True}
print()
# -----------------------------------------------------------------------------
# Creating an empty dictionary.
# -----------------------------------------------------------------------------
empty_dictionary = {}
# -----------------------------------------------------------------------------
# Displaying the empty dictionary.
# -----------------------------------------------------------------------------
print("Empty Dictionary :", empty_dictionary)
# Output:
# Empty Dictionary : {}
print()
# -----------------------------------------------------------------------------
# Displaying the type of the dictionary.
# -----------------------------------------------------------------------------
print("Type of student :", type(student))
# Output:
# Type of student : <class 'dict'>