Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Output of Python programs | Set 7
Next article icon

Output of Python Programs | Set 24 (Dictionary)

Last Updated : 06 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Prerequisite :

Python-Dictionary

1. What will be the output?

Python
dictionary = {"geek":10, "for":45, "geeks": 90} print("geek" in dictionary) 

Options:

  1. 10
  2. False
  3. True
  4. Error
Output:
3. True

Explanation:

in

is used to check the key exist in dictionary or not.

2. What will be the output?

Python
dictionary ={1:"geek", 2:"for", 3:"geeks"} del dictionary 

Options:

  1. del deletes the entire dictionary
  2. del doesn’t exist for the dictionary
  3. del deletes the keys in the dictionary
  4. del deletes the values in the dictionary
Output:
1. del deletes the entire dictionary

Explanation:

del

deletes the entire dictionary and any further attempt to access it will throw an error.

3. What will be the output?

Python
a = {} a[1] = 1 a['1'] = 2 a[1]= a[1]+1 count = 0 for i in a:     count += a[i] print(count) 

Options:

  1. 4
  2. 2
  3. 1
  4. Error
Output:
1. 4

Explanation:

The above piece of code basically finds the sum of the values of keys.

4. What will be the output?

Python
test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test)) 

Options:

  1. 2
  2. 1
  3. 0
  4. Error
Output:
1. 2

Explanation:

After the key-value pair of 1:’A’ is deleted, the key-value pair of 1:’D’ is added.

5. What will be the output?

Python
a ={} a['a']= 1 a['b']=[2, 3, 4] print(a) 

Options:

  1. {‘b’: [2], ‘a’: 1}
  2. {‘a’: 1, ‘b’: [2, 3, 4]}
  3. {‘b’: [2], ‘a’: [3]}
  4. Error
Output:
2. {'a': 1, 'b': [2, 3, 4]}

Explanation:

Mutable members can be used as the values of the dictionary but they cannot be used as the keys of the dictionary.



Next Article
Output of Python programs | Set 7

A

Abhishek Sharma 44
Improve
Article Tags :
  • Python
  • Python Programs
  • python-dict
Practice Tags :
  • python
  • python-dict

Similar Reads

  • Output of Python Program - Dictionary (set 25)
    Prerequisite: Dictionaries in PythonThese question sets will make you conversant with Dictionary Concepts in Python programming language. Question 1: Which of the following is true about Python dictionaries? A. Items are accessed by their position in a dictionary. B. All the keys in a dictionary mus
    3 min read
  • Output of Python programs | Set 9 (Dictionary)
    Prerequisite: Dictionary 1) What is the output of the following program? [GFGTABS] Python dictionary = {'GFG' : 'geeksforgeeks.org', 'google' : 'google.com', 'facebook' : 'facebook.com' } del dictionary['google']; for key, values in dictionary.
    3 min read
  • Output of Python Programs | (Dictionary)
    Prerequisite: Dictionary Note: Output of all these programs is tested on Python3 1.What is the output of the following of code? a = {i: i * i for i in range(6)} print (a) Options: a) Dictionary comprehension doesn’t exist b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36} c) {0: 0, 1: 1, 4: 4, 9: 9, 16
    2 min read
  • Output of Python programs | Set 8
    Prerequisite - Lists in Python Predict the output of the following Python programs. Program 1 [GFGTABS] Python list = [1, 2, 3, None, (1, 2, 3, 4, 5), ['Geeks', 'for', 'Geeks']] print len(list) [/GFGTABS]Output: 6Explanation: The beauty of python list datatype is that within
    3 min read
  • Output of Python programs | Set 7
    Prerequisite - Strings in Python Predict the output of the following Python programs. These question set will make you conversant with String Concepts in Python programming language. Program 1[GFGTABS] Python var1 = 'Hello Geeks!' var2 = "GeeksforGeeks" print "var1[0]: ",
    3 min read
  • Output of Python Programs | Set 22 (Loops)
    Prerequisite: LoopsNote: Output of all these programs is tested on Python3 1. What is the output of the following?[GFGTABS] Python mylist = ['geeks', 'forgeeks'] for i in mylist: i.upper() print(mylist) [/GFGTABS][‘GEEKS’, ‘FORGEEKS’].[‘geeks’, ‘forgeeks’].[None, None].Unexpected Out
    2 min read
  • Output of Python program | Set 5
    Predict the output of the following programs: Program 1: [GFGTABS] Python def gfgFunction(): "Geeksforgeeks is cool website for boosting up technical skills" return 1 print (gfgFunction.__doc__[17:21]) [/GFGTABS]Output: coolExplanation: There is a docstring defined for this method,
    3 min read
  • Output of Python programs | Set 10 (Exception Handling)
    Pre-requisite: Exception Handling in PythonNote: All the programs run on python version 3 and above. 1) What is the output of the following program? [GFGTABS] Python data = 50 try: data = data/0 except ZeroDivisionError: print('Cannot divide by 0 ', end = '') else: print('Divisio
    3 min read
  • Output of Python Program | Set 1
    Predict the output of following python programs: Program 1: [GFGTABS] Python r = lambda q: q * 2 s = lambda q: q * 3 x = 2 x = r(x) x = s(x) x = r(x) print (x) [/GFGTABS]Output: 24Explanation : In the above program r and s are lambda functions or anonymous functions and q is the argument to both of
    3 min read
  • Output of Python program | Set 15 (Loops)
    Prerequisite - Loops in Python Predict the output of the following Python programs. 1) What is the output of the following program? [GFGTABS] Python x = ['ab', 'cd'] for i in x: i.upper() print(x) [/GFGTABS]Output:['ab', 'cd']Explanation: The function upper() does not modify a string
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences