Computer Science, asked by subhi47, 1 year ago

explain dictionary data type and list data type in Python with examples​

Answers

Answered by shefalibajaj2810
7

Answer:

Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

There are various data types in Python.

1. List

2. Dictionary

3. Sets

4. Tuples

LIST:

List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.

Declaring a list is pretty straight forward. Items separated by commas are enclosed within square brackets [ ].

eg:        >>> a = [1, 2.2, 'python']

type(a)

<class 'list'>

DICTIONARY:

Dictionary is an unordered collection of key-value pairs.

It is generally used when we have a huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to retrieve the value.

In Python, dictionaries are defined within curly braces { } with each item being a pair in the form key:value. Key and value can be of any type.

eg:    d = {1:'value','key':2}

type(d)

<class 'dict'>

Explanation:

Similar questions