How to Creating a dictionary in Python datatypes-Python Dictionary and Dict

How to Creating a dictionary in Python datatypes 

three ways to create a dictionary.


Using curly brackets: The dictionaries are created by enclosing the comma-separated Key: Value pairs inside the {} curly brackets. The colon ‘:‘ is used to separate the key and value in a pair.

Creating a dictionary in Python

ex:

employee = {"empname": "raemsh", "jobdesc": "Software Developer", "salary":88000}

print(employee)


Using dict() constructor:  Create a dictionary by passing the comma-separated key: value pairs inside the dict().

ex:

emp=dict({"empname":"krishna","jobdesc":"Python Developer","salaru":120000})

print(emp)


Using sequence having each item as a pair (key-value)

ex:

emp=dict([("empname","ravikrishna"),("jobdesc","software developer"),("salary",130000)])

print(emp)


# create dictionary with value as a list

ex:

emp = {"empname": "mohan rao", "empnumber": [987, 654,3210]}

print(emp)




#Creating a dictionary in Python, #creating python dictionary, #python dict(), #python dict constructor, #python jobs, #python programming, #python development





No comments:

Post a Comment

Latest Post

How to Generate Barcode and QR code For Our Products

 మీ products కి barcode / QR code generate చేయాలంటే OPTION 1: ONLINE (No Coding – Quick) Best for small shops / beginners 👉Free websites: T...