Python Dictionary keys() Method (2024)

❮ Dictionary Methods

Definition and Usage

The keys() method returns a view object. The view object contains the keys of the dictionary, as a list.

The view object will reflect any changes done to the dictionary, see example below.

Syntax

dictionary.keys()

Parameter Values

No parameters

More Examples

Example

When an item is added in the dictionary, the view object also gets updated:

car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}

x = car.keys()

car["color"] = "white"

print(x)

Try it Yourself »

❮ Dictionary Methods

W3schools Pathfinder

Track your progress - it's free!

Python Dictionary keys() Method (2024)
Top Articles
Latest Posts
Article information

Author: Chrissy Homenick

Last Updated:

Views: 6066

Rating: 4.3 / 5 (74 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Chrissy Homenick

Birthday: 2001-10-22

Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

Phone: +96619177651654

Job: Mining Representative

Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.