Skip to content

Spoke Right

Education for everyone

https://spokeright.com
Primary Menu
  • Home
  • Our Services
    • Translation
    • Interpretation
    • Transcription
    • Voice-Over
    • Proofreading
    • Content writing
  • Free Education
    • Learn Android Studio
    • Learn Python
    • Learn MongoDB
    • Learn MySql
    • Learn React
    • Montessori Education
  • Spoke Right News
  • Earn Online
  • Classic Games by Spoke Right
    • TicTac
    • Checkers
    • Foosball
    • Billiards
    • Master Chess
    • Logic Game
  • Contact Us
Download Now
  • Home
  • Learn Python
  • What is python dictionary in python
  • Learn Python

What is python dictionary in python

Spoke Right December 6, 2022 2 min read

Pyhton Dictionary

A dictionary is a collection or an associative array which is used to store various types of data.

Features of Python Dictionaries:

  • They are unordered and changeable.
  • They are written within curly brackets.
  • They can store multiple types of data.
  • They are mutable. Thus, the current values in the dictionary can be modified.
  • Keys are immutable. Thus, it can not be modified.
  • Python Dictionaries supports various operations.
  • The complete pair of key and value is called as a dictionary item.
  • The key passed in each dictionary item must be unique.
  • The key and the value is separated by a colon(:).
  • Items are separated from each other by a comma(,).
  • Value in a dictionary can be accessed by its key.

Python Dictionaries Methods:

METHODSUSES
clear()To remove all the elements from the dictionary.
cmp()To compare two dictionaries.
copy()To get a copy of the dictionary.
fromkeys()To get a dictionary with the specified keys and values.
get()To get the value of the specified key.
items()To get a list containing the a tuple for each key value pair.
 keys()To get a list containing the dictionary’s keys.
len()To get the number of items in a dictionary.
pop()To get the element with the specified key.
 popitem()To remove the last key-value pair.
setdefault()To get the value of the specified key. If the key does not exist: insert the key, with the specified value.
str()To get the string representation of a dictionary.
update()To update the dictionary with the specified key-value pairs.
values()To get a list of all the values in the dictionary.

Example:

a =  { "1": "python",
"2": "java",
  "3": "php",
   "4": "HTML",
    "5": "javascript",
     "6": "CSS",
      "7": "Bootstrap"}
print "\n"
print "Dictionary is:"
print a
print "\n"
 
print "Get the value of the key 1."
print(a["1"])
print "\n"
 
print "Get the total length."
print(len(a))
print "\n"
 
print "Delete the item."
del a["5"]
print a
print "\n"
 
print "Replace a value."
a["3"] = "jQuery"
print a
print "\n"
 
print "Add a value."
a["9"] = "C"
print a
print "\n"

Continue Reading

Previous: What are tuples in Python
Next: What are Python functions

Related Stories

What is Data Statistics And Analysis With Java And Python
9 min read
  • Learn Python

What is Data Statistics And Analysis With Java And Python

December 7, 2022
How do I get the date in Python
2 min read
  • Learn Python

How do I get the date in Python

December 7, 2022
What is an exception handler in Python
2 min read
  • Learn Python

What is an exception handler in Python

December 7, 2022

This AD Will support Us

Support Us

Coding Ustad LTD Support
Coding Ustad LTD Support

Coding Ustad LTD

Coding Ustad LTD
Coding Ustad LTD

Recent Posts

  • How to Install Node.js and npm on CentOS 7
  • How to Install Node.js and npm on CentOS 7
  • How to Install CentOS Web Panel (CWP) on CentOS 7
  • The Power of Marketing in Real Estate: A Guide to Boost Your Business
  • Vehicle Verification in Pakistan

Get free Hosting

Hostens.com - A home for your website

You may have missed

How to Install Node.js and npm on CentOS 7
4 min read
  • Coding Ustad LTD
  • Education for Everyone

How to Install Node.js and npm on CentOS 7

May 3, 2023
How to Install Node.js and npm on CentOS 7
4 min read
  • Coding Ustad LTD
  • Education for Everyone

How to Install Node.js and npm on CentOS 7

May 2, 2023
How to Install CentOS Web Panel (CWP) on CentOS 7
3 min read
  • Coding Ustad LTD
  • Education for Everyone

How to Install CentOS Web Panel (CWP) on CentOS 7

May 2, 2023
The Power of Marketing in Real Estate: A Guide to Boost Your Business https://thaikadar.com/secureinvestment/
2 min read
  • Article By Spoke Right
  • Blog By Spoke Right
  • Circular Byte Private Limited

The Power of Marketing in Real Estate: A Guide to Boost Your Business

January 30, 2023
  • Home
  • Our Services
  • Free Education
  • Spoke Right News
  • Earn Online
  • Classic Games by Spoke Right
  • Contact Us
Copyright © All rights reserved. | MoreNews by AF themes.