Dictionary in Python
α Python programming language dictionary α¨αα£αα α key-value α₯αα΅ ααα α¨αααα‘ elements α΅α₯α΅α₯ ααα’ Key α¨ααα ααα α¨α«ααα corresponding value acess αα΅α¨α α΅αααα ααα’
Dictionaries α¨αα α αα΅ α΅αlists α΅ααα α₯αα³α¨αα mutable ααΈαα£ αα α ααα΅ listα‘ α¨α°αα α¨ α αα elementα¦αΉα modify αα¨α α₯αα½αααα’
α python dictionary αααα α curly braces '{}' αα α¨ααα ααα α¨αα key-value pair α colon ':' α₯ααα«ααα’
ααα³αα‘
my_dict = {'key1': 'value1', 'key2': 'value2'}You can access values in a dictionary by referencing the key in square brackets ([]).
ααα³α :
print(my_dict['key1']) # Output: value1
ααα α°αα α¨α±αα«α© methods α₯α functions α αα αα α¨dictionary α α²α΅ elements αα¨αα α£ α«αα΅α modify αα¨αα£ delete αα¨α α₯αα½ααα
Dictionaries are commonly used in Python for storing data that needs to be looked up quickly using a unique key.
Dictionaries α Python αα΅α₯ key α αα αα α αα₯αα΅ αααα α«αα£αΈαα αα¨ααα½ ααα¨ααΈα΅ α α₯αα΅ α₯α α αα ααααα’
#Dictionary
#DataTypes
@python_pioneers
β‘2π1π₯1
Python Pioneers: A Beginner's Guide πͺπΉ
Dictionary in Python α Python programming language dictionary α¨αα£αα α key-value α₯αα΅ ααα α¨αααα‘ elements α΅α₯α΅α₯ ααα’ Key α¨ααα ααα α¨α«ααα corresponding value acess αα΅α¨α α΅αααα ααα’ Dictionaries α¨αα
α αα΅ α΅αlists α΅ααα α₯αα³α¨αα mutable ααΈαα£ αα
α ααα΅ listα‘ α¨α°αα α¨ α αα elementα¦αΉαβ¦
Example of Creating and Using a Dictionary:
#Dictionary
#DataTypes
@python_pioneers
# Creating a dictionary
student_info = {
"name": "John Doe",
"age": 17,
"grade": "11th",
"subjects": ["Math", "Science", "English"]
}
# Accessing dictionary values by key
print(student_info["name"]) # Output: John Doe
# Adding a new key-value pair
student_info["hobby"] = "Reading"
print(student_info) # Adds 'hobby': 'Reading' to the dictionary
# Modifying an existing key's value
student_info["grade"] = "12th"
print(student_info["grade"]) # Output: 12th
# Removing a key-value pair using 'pop'
student_info.pop("age")
print(student_info) # Removes 'age' from the dictionary
# Looping through keys and values
for key, value in student_info.items():
print(key, value)
# Checking if a key exists in the dictionary
if "name" in student_info:
print("Key 'name' exists!")
#Dictionary
#DataTypes
@python_pioneers
π2
Python Data Types at a Glance
Hey Python Pioneers! π¨βπ»π©βπ»
Here are basic data types in Python you should know:
int β integers (e.g. 5, -10)
float β decimal numbers (e.g. 3.14, -0.001)
str β text or strings (e.g. "Hello World")
bool β True or False
list β ordered, changeable collection (e.g. [1, 2, 3])
dict β key-value pairs (e.g. {"name":"Abebe"})
tuple β ordered, unchangeable collection (e.g. (1, 2, 3))
set β unordered unique items (e.g. {1, 2, 3})
#DataTypes
@python_pioneers
Hey Python Pioneers! π¨βπ»π©βπ»
Here are basic data types in Python you should know:
int β integers (e.g. 5, -10)
float β decimal numbers (e.g. 3.14, -0.001)
str β text or strings (e.g. "Hello World")
bool β True or False
list β ordered, changeable collection (e.g. [1, 2, 3])
dict β key-value pairs (e.g. {"name":"Abebe"})
tuple β ordered, unchangeable collection (e.g. (1, 2, 3))
set β unordered unique items (e.g. {1, 2, 3})
#DataTypes
@python_pioneers
β€2