Day 27 Of Documenting My Learning Journey

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5168

    #1

    Day 27 Of Documenting My Learning Journey

    What I learnt Today

    1. How to define dictionaries using dict constructor and curly braces {}
    2. How to access elements in a list usin the .get method() and variable name with brackets[]
    3. How to add and update elements in dictionary
    4. How to loop through keys , values and both keys and values using a for loop.


    On what I learnt Today

    Assumption: We have a dictionary of the name Person.


    Syntax:

    1. Defining: person = {
      "name" : "James" ,
      "age" : 23 ,
      "Occupation" : "Engineer"
      }
    2. Accessing Elements = print(person["name"]) OR print(person.get("name"))
    3. Adding Elements in a Dictionary

      person["status"] = "Graduated"
    4. Updating elements in a Dictionary.

      person["age"] = 20
    5. Removing an Element from a Dictionary

      person.pop("status")
    6. Looping through respecive keys

      for key in person:

      print(key)
    7. Looping through respective Values

      for value in person.values():

      print(value)
    8. Looping through respective keys and Values

      for key , value in person.items():

      print(f"{key} -> {value}")


    Resources I used

    Python refresher series by Bonaventure Ogeto on Youtube.


    What's Next

    Understanding sets and Tuples.




    More...
Working...