+ 1

Python

How to work with dictionary and modules

3rd Mar 2025, 2:15 AM
Ruben L Donzo
Ruben L Donzo - avatar
3 Respostas
+ 4
You can learn them in Python courses, such as Python Developer: https://www.sololearn.com/learn/courses/python-developer Still here's the basics: Dictionary: Dictionary is a collection of key-value pairs, each key holding a value. Like here, where name holds "Alan" and age holds 20: person = { "name": "Alan", "age": 20 } Access values: print(person) # Outputs the dictionary print(person["name"]) # Outputs "Alan" Add, update and remove values: person["name"] = "John" # Value of 'name' is "John" person["profession"] = "Programmer" # Added new key 'profession' with value "Programmar" person.pop["age"] # Removes the key-value pair of "age" Module: Modules are files that have variables, classes, functions and more set-up in a way that you can reuse them in your code to make tasks easier and optimized. Import a module with import: import math Using a math function: print(math.sqrt(25)) #square root of 25 Learn more about these in Python course and other resources 👍
3rd Mar 2025, 3:18 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
3rd Mar 2025, 4:03 PM
Erik J
0
Creating a module: Save your functions or variables in a .py file, and you can import them into other Python scripts. Importing modules: You use the import keyword to access the functionality of the module. Using functions from the module: You can call the functions or access variables as needed.
3rd Mar 2025, 7:27 PM
Badshan Gaming
Badshan Gaming - avatar