Python Dictionary

in #python5 years ago

How to create dictionary in Python?

(curly braces) {} creates a key-value pair with a colon (:) in the bracket and a single dictionary is created separately with a comma (,) for each pair. In addition, you can also create a dictionary with the dict () function. Let's look at some examples:

Try this code:

# empty dictionary

my_dict = {}

# dictionary with integer keys

my_dict = {1: 'apple', 2: 'ball'}

# dictionary with mixed keys

my_dict = {'name': 'Maruf', 1: [2, 4, 3]}

# using dict()

my_dict = dict({1:'apple', 2:'ball'})

# from sequence having each item as a pair

my_dict = dict([(1,'apple'), (2,'ball')])


This post has been upvoted from Steemit Bangladesh, @steemitbd. It's the first steemit community project run by Bangladeshi steemians to empower youths from Bangladesh through STEEM blockchain. If you are from Bangladesh and looking for community support, Join Steemit Bangladesh Discord Server.

If you would like to delegate to the Steemit Bangladesh, you can do so by clicking on the following links:

50 SP, 100 SP, 250 SP, 500 SP, 1000 SP.


Coin Marketplace

STEEM 0.21
TRX 0.06
JST 0.026
BTC 27721.36
ETH 1754.45
USDT 1.00
SBD 2.85