Dictionary in Python
Dictionary It is a mutable data-type (you can change the values in-place, don't worry we will discuss further about mutability). Contains key-value pair. Values are accessed using keys, not index unlike in list and tuples. It is an ordered data-type. Dictionary doesn't allow duplicate keys. Now let's start practical session where we will learn how to create an empty dictionary, how to access values from a dictionary using keys, functions of dictionary: Create an empty dictionary: There are different ways to create an empty dictionary in python: 1. Using Curly Braces: student = {} print(student) #output: {} print(type(student)) #output: <class 'dict'> 2. Using a built-in function dict(): student = dict() print(student) #output: {} You saw that we were able to create an empty dictionary using both methods. Both set and dictionary are denoted by {}. In first block, I have used a type() function (returns data...
Comments
Post a Comment