Header Ads

Responsive Ads Here

in keyword and looping on dictionaries

 in Keyword and looping on Dictionaries



d = {"name" : "Adrika",
     "age": 14,
     "class" : 9,
     "d1": {"name" : "Anika", "age": 3, "class" : 2}}

# Using in keyword
if "name" in d:
    print("Yes")
else:
    print("No")

# Looping on dictionaries
# Looping on keys
for i in d:
    print(i)

# Looping on values
for i in d:   # method 1
    print(d[i])

for i in d.values():  # method 2
    print(i)

Powered by Blogger.