1

Please I want to know how python recognizes that skill is the key of mySkills dictionary.

mySkills = {
  "Html": "90%",
  "Css": "60%",
  "PHP": "70%",
  "JS": "80%",
  "Python": "90%",
  "MySQL": "60%"
}


for skill in mySkills:

  # print(skill)

  print(f"My Progress in Lang {skill} Is: {mySkills.get(skill)}")
Ahmed Ali
  • 21
  • 3
  • 5
    The default behavior of `dict.__iter__` is to iterate over the keys. `skill` is a name that *you* have defined to represent each key - you can name it whatever you want. – 0x5453 Aug 27 '21 at 17:50
  • Because it's the variable you used in the loop: `for skill in mySkills`, the *name* is irrelevant, you could use `for banana in mySkills: print(mySkills.get(banana))` – juanpa.arrivillaga Aug 27 '21 at 17:54

1 Answers1

2
for skill in mySkills:

read this as a for each skill in mySkills, it would make more sense.

also, skill is a user defined variable.

in this line :

print(f"My Progress in Lang {skill} Is: {mySkills.get(skill)}")

basically you are saying My Progress in Lang for each item of mySkills one by one, Is: get the item value.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38