Foro de Python


Cómo hacer un bucle en Python

Aquí tienes una guía básica para crear bucles en Python:




Categorías

General

Discusiones generales sobre Python.

Explorar

Django

Preguntas y respuestas relacionadas con el framework Django.

Explorar

Flask

Todo sobre el framework Flask para aplicaciones web.

Explorar

Miembros Destacados

Lion21:3

Activo desde: 2022-01-01

Ver perfil

Steve09

Activo desde: 2022-02-01

Ver perfil

Uso del diccionario en Python



# Create a dictionary of English names and their meanings
name_dictionary = {
    "John": "God is gracious",
    "Emily": "Industrious",
    "Michael": "Who is like God",
    "Sophia": "Wisdom",
    "Daniel": "God is my judge"
}

# Access a value in the dictionary
print(name_dictionary["Emily"])  # Output: Industrious

# Add a new key-value pair to the dictionary
name_dictionary["Emma"] = "Universal"

# Modify an existing value in the dictionary
name_dictionary["Sophia"] = "Feminine wisdom"

# Remove an entry from the dictionary
del name_dictionary["Michael"]

# Check if a key exists in the dictionary
if "Daniel" in name_dictionary:
    print("The meaning of 'Daniel' is:", name_dictionary["Daniel"])
else:
    print("The name 'Daniel' is not in the dictionary")

# Iterate over the keys of the dictionary
for name in name_dictionary:
    print(name, "->", name_dictionary[name])


Contacto