Skip to content
Vista Academy
  • Home
  • About Us
  • Course
    • Master Program in Data Analytics Course
    • Master Program in Data Science Course
    • Master Program Business Analytics Course
    • 3‑Month Machine Learning Course
    • Human Intelligence Internship in the Age of AI | Vista Academy
  • Explore Our Courses
  • Gallery & Achievements
  • Blog
    • Data Analytics
    • artificial intelligence
    • Career & Salary
    • Data Dashboards – Uttarakhand Insights
    • informationTechnology
    • Power BI
    • python
    • SQL
    • Projects
  • Free Data Analytics Tools for Students
    • Free Dataset Finder
    • Data Analyst Resume Builder
    • Data Analytics Jobs
    • Data Analytics Roadmap 2026
  • Contact Us
  • Home
  • Explore Our Courses
  • Written Edition English Tutorial

Python Written Edition English Tutorial

Curriculum

  • 15 Sections
  • 167 Lessons
  • 10 Weeks
Expand all sectionsCollapse all sections
  • Python Basics
    54
    • 1.1
      Introduction to Python Programming
    • 1.2
      Python Overview: Features, Applications & Why It’s So Popular
    • 1.3
      MCQ Python – Overview
      10 Minutes4 Questions
    • 1.4
      Python History & Versions Explained: Evolution of the Language
    • 1.5
      MCQ History and Versions of Python
      10 Minutes4 Questions
    • 1.6
      Top Python Features: Why Python is So Popular
    • 1.7
      MCQ Python features
      10 Minutes4 Questions
    • 1.8
      Python vs C++: Key Differences for Beginners & Developers
    • 1.9
      MCQ Python vs C++
      10 Minutes4 Questions
    • 1.10
      Python Hello World Program – Your First Step in Coding
    • 1.11
      MCQ Hello World program in Python
      10 Minutes2 Questions
    • 1.12
      Top Applications of Python in Real Life | Python Career Scope
    • 1.13
      Python Interpreter & Modes Explained | Interactive vs Script Mode
    • 1.14
      MCQ Python Interpreter and Its Modes
      10 Minutes4 Questions
    • 1.15
      Python Environment Setup | Install Python, IDEs & Configure Path
    • 1.16
      MCQ Python Environment Setup: A Complete Guide
      10 Minutes4 Questions
    • 1.17
      Python Syntax Basics | Learn How Python Code is Written
    • 1.18
      MCQ Python – Syntax
      10 Minutes4 Questions
    • 1.19
      Python Variables Explained | Learn to Store and Use Data in Python
    • 1.20
      MCQ Python – Variables
      10 Minutes4 Questions
    • 1.21
      Assign Multiple Values to Python Variables | Python Tutorial for Beginners
    • 1.22
      MCQ Python Variables – Assign Multiple Values
      10 Minutes4 Questions
    • 1.23
      Python Data Types Explained | Built-in Data Types in Python
    • 1.24
      MCQ PYTHON DATA TYPE
      10 Minutes5 Questions
    • 1.25
      Python Type Casting | Convert Data Types in Python
    • 1.26
      MCQ Python – Type Casting
      10 Minutes4 Questions
    • 1.27
      Python Unicode System | Handle Multilingual Text in Python
    • 1.28
      MCQ Python Unicode System
      10 Minutes4 Questions
    • 1.29
      Python Literals Explained | Types, Examples & Use Cases
    • 1.30
      MCQ Python Literals: A Comprehensive Guide
      15 Minutes5 Questions
    • 1.31
      Python Operators Explained | Types, Syntax & Examples
    • 1.32
      MCQ Python – Operators
      15 Minutes5 Questions
    • 1.33
      Mastering Python Arithmetic Operators with Examples
    • 1.34
      MCQ Python arithmetical operator
      20 Minutes15 Questions
    • 1.35
      Python Comparison Operators Explained with Examples
    • 1.36
      MCQ Python – Comparison Operators
      10 Minutes4 Questions
    • 1.37
      Mastering Python Assignment Operators with Examples
    • 1.38
      MCQ Python Assignment Operators:
      10 Minutes4 Questions
    • 1.39
      Python Logical Operators Explained with Examples
    • 1.40
      MCQ Python Logical Operators
      10 Minutes4 Questions
    • 1.41
      Python Bitwise Operators Explained with Examples
    • 1.42
      Python Membership Operators Explained with Examples
    • 1.43
      MCQ Python – Membership Operators
      10 Minutes4 Questions
    • 1.44
      Python Identity Operators: is and is not Explained
    • 1.45
      MCQ Python Identity Operators
      10 Minutes4 Questions
    • 1.46
      Understanding Python Identity Operators with Examples
    • 1.47
      MCQ PYTHON IDENTITY OPERATOR
      10 Minutes4 Questions
    • 1.48
      Python Comments: Single-line and Multi-line Explained
    • 1.49
      Taking User Input in Python with input() Function
    • 1.50
      MCQ Provide User Input in Python
      10 Minutes2 Questions
    • 1.51
      Python Numbers: int, float, and complex Explained
    • 1.52
      MCQ Python – Numbers
      10 Minutes2 Questions
    • 1.53
      Python Booleans (bool): True and False Explained with Examples
    • 1.54
      MCQ Python Booleans (bool)
      10 Minutes4 Questions
  • Python Control Statements
    25
    • 2.1
      Python Control Flow: Master if, else, elif Statements with Examples
    • 2.2
      Python Decision Making: if, elif, else Explained with Examples
    • 2.3
      MCQ Python – Decision Making
      10 Minutes4 Questions
    • 2.4
      Python if Statement: Basic Conditional Execution in Python
    • 2.5
      MCQ Python – if Statement
      10 Minutes4 Questions
    • 2.6
      Python if-else Statement: Make Conditional Decisions in Python
    • 2.7
      Python Nested if Statement: Master Conditional Logic in Depth
    • 2.8
      MCQ Python – Nested if Statement Python if-else Statement
      10 Minutes4 Questions
    • 2.9
      Python Match-Case Statement: Simplify Multiple Conditions Easily
    • 2.10
      (MCQs) based on the Python Match-Case Statement
      10 Minutes4 Questions
    • 2.11
      Python Loops Explained: Master for, while, and nested loops
    • 2.12
      Python For Loops Tutorial: Syntax, Range, and Examples
    • 2.13
      MCQ Python – For Loops
      10 Minutes2 Questions
    • 2.14
      Python For Else Loop Explained with Examples
    • 2.15
      MCQ Python – For Else Loop
      10 Minutes4 Questions
    • 2.16
      Python While Loops with Syntax and Real Examples
    • 2.17
      MCQ Python – While Loops
      10 Minutes4 Questions
    • 2.18
      Python break Statement with Syntax, Flowchart & Examples
    • 2.19
      MCQ Python – break Statement
      10 Minutes4 Questions
    • 2.20
      Python continue Statement Explained with Syntax and Practical Examples
    • 2.21
      MCQ Python – Continue Statement
      10 Minutes4 Questions
    • 2.22
      Python pass Statement: Usage, Syntax, and Examples
    • 2.23
      MCQ Python – pass Statement
      10 Minutes4 Questions
    • 2.24
      Python Nested Loops: Complete Guide with Syntax and Examples
    • 2.25
      Mcq Python – Nested Loops
      10 Minutes4 Questions
  • Python Functions & Modules
    16
    • 3.1
      Python Functions: A Complete Guide with Syntax and Examples
    • 3.2
      MCQ Python – Functions
      10 Minutes4 Questions
    • 3.3
      Python Default Arguments Explained with Syntax and Real Examples
    • 3.4
      mcq Python – Default Arguments
      10 Minutes2 Questions
    • 3.5
      Python Keyword Arguments Explained with Syntax and Practical Examples
    • 3.6
      MCQ Python Keyword Arguments Explained
      10 Minutes4 Questions
    • 3.7
      Python Keyword-Only Arguments: Syntax, Examples, and Use Cases
    • 3.8
      Python Positional Arguments: A Beginner-Friendly Guide with Examples
    • 3.9
      MCQ Positional Arguments Keyword-Only Arguments
      10 Minutes4 Questions
    • 3.10
      Python Arbitrary (Variable-Length) Arguments Explained with Examples
    • 3.11
      MCQ Python – Arbitrary or, Variable-length Arguments
      10 Minutes4 Questions
    • 3.12
      Python Variable Scope Explained: Local, Global, and Nonlocal with Examples
    • 3.13
      MCQ Python Variable Scope
      10 Minutes4 Questions
    • 3.14
      Python Function Annotations: Add Meaning to Function Parameters and Return Types
    • 3.15
      MCQ Python – Function Annotations
      10 Minutes5 Questions
    • 3.16
      Python Modules: Create, Import, and Use Python Code Reusably
  • Python Strings
    14
    • 4.1
      Python Strings: Learn String Creation, Methods & Manipulation
    • 4.2
      MCQ Python – Strings
      10 Minutes4 Questions
    • 4.3
      Python Slicing Strings: Learn Indexing & Substring Extraction Easily
    • 4.4
      MCQ Python Slicing Strings
      10 Minutes4 Questions
    • 4.5
      Python Modify Strings: Learn How to Change and Update Strings
    • 4.6
      MCQ Python – Modify Strings
      10 Minutes4 Questions
    • 4.7
      Python String Concatenation: Combine Strings Easily
    • 4.8
      MCQ Python – String Concatenation
      10 Minutes4 Questions
    • 4.9
      Python String Formatting: Format Strings with Style
    • 4.10
      MCQ Python – String Formatting
      10 Minutes4 Questions
    • 4.11
      Python Escape Characters: Handle Special Characters in Strings
    • 4.12
      MCQ Python – Escape Characters
      10 Minutes4 Questions
    • 4.13
      Python String Methods: Essential Functions for String Handling
    • 4.14
      MCQ Python – String Methods
      10 Minutes4 Questions
  • Python Lists
    22
    • 5.1
      Python Lists Tutorial: Creating, Accessing, and Modifying Lists
    • 5.2
      MCQ Python – Lists
      10 Minutes4 Questions
    • 5.3
      Accessing List Items in Python with Indexing and Slicing
    • 5.4
      MCQ Python – Access List Items
      10 Minutes4 Questions
    • 5.5
      How to Change List Items in Python with Examples
    • 5.6
      MCQ Python – Change List Items
      10 Minutes4 Questions
    • 5.7
      How to Add Items to a List in Python with Examples
    • 5.8
      MCQ Python – Add List Items
      10 Minutes4 Questions
    • 5.9
      How to Remove Items from a List in Python with Examples
    • 5.10
      MCQ Python – Remove List Items
      10 Minutes4 Questions
    • 5.11
      Loop Through Lists in Python with For and While Loops
    • 5.12
      MCQ Python – Loop Lists
      10 Minutes4 Questions
    • 5.13
      Master Python List Comprehension with Simple Examples
    • 5.14
      MCQ Python – List Comprehension
      10 Minutes4 Questions
    • 5.15
      How to Sort Lists in Python with Examples
    • 5.16
      MCQ Python – Sort Lists
      10 Minutes4 Questions
    • 5.17
      Different Ways to Copy Lists in Python with Examples
    • 5.18
      MCQ Python – Copy Lists
      10 Minutes4 Questions
    • 5.19
      Python – Join Lists
    • 5.20
      MCQ Python – Join Lists
      10 Minutes4 Questions
    • 5.21
      Essential Python List Methods with Examples
    • 5.22
      MCQ List Methods
      10 Minutes4 Questions
  • Python Tuples
    14
    • 6.1
      Understanding Tuples in Python with Practical Examples
    • 6.2
      MCQ Python – Tuples
      10 Minutes4 Questions
    • 6.3
      Python – Access Tuple Items
    • 6.4
      MCQ Access Tuple Items
      10 Minutes4 Questions
    • 6.5
      How to Update Tuples in Python with Smart Workarounds
    • 6.6
      MCQ Update Tuples
      10 Minutes4 Questions
    • 6.7
      Python – Unpack Tuple Items
    • 6.8
      MCQ Unpack Tuple Items
      10 Minutes4 Questions
    • 6.9
      Python – Loop Tuples
    • 6.10
      MCQ Loop Tuples
      10 Minutes4 Questions
    • 6.11
      Python – Join Tuples
    • 6.12
      MCQ Join Tuples
      10 Minutes4 Questions
    • 6.13
      Python – Tuple Methods
    • 6.14
      MCQ Tuple Methods
      10 Minutes4 Questions
  • Python Sets
    18
    • 7.1
      Python Sets Tutorial with Examples for Beginners
    • 7.2
      MCQ Sets
      10 Minutes4 Questions
    • 7.3
      Accessing Items in Python Sets with Examples
    • 7.4
      MCQ Access Set Items
      10 Minutes4 Questions
    • 7.5
      Python – Add Set Items
    • 7.6
      MCQ Add Set Items
      10 Minutes4 Questions
    • 7.7
      Python – Remove Set Items
    • 7.8
      MCQ Remove Set Items
      10 Minutes4 Questions
    • 7.9
      Python – Loop Sets
    • 7.10
      MCQ Loop Sets
      10 Minutes4 Questions
    • 7.11
      Python – Join Sets
    • 7.12
      MCQ Join Sets
      10 Minutes4 Questions
    • 7.13
      Python – Copy Sets
    • 7.14
      MCQ Copy Sets
      10 Minutes4 Questions
    • 7.15
      Python – Set Operators
    • 7.16
      MCQ Set Operators
      10 Minutes4 Questions
    • 7.17
      Python – Set Methods
    • 7.18
      MCQ Set Methods
      10 Minutes4 Questions
  • Python Dictionaries
    20
    • 8.1
      Python – Dictionaries
    • 8.2
      MCQ Dictionaries
      10 Minutes4 Questions
    • 8.3
      Python – Access Dictionary Items
    • 8.4
      MCQ Access Dictionary Items
      10 Minutes4 Questions
    • 8.5
      Python – Change Dictionary Items
    • 8.6
      MCQ Change Dictionary Items
      10 Minutes4 Questions
    • 8.7
      Python – Add Dictionary Items
    • 8.8
      MCQ Add Dictionary Items
      10 Minutes4 Questions
    • 8.9
      Python – Remove Dictionary Items
    • 8.10
      MCQ Remove Dictionary Items
      10 Minutes4 Questions
    • 8.11
      Python – Dictionary View Objects
    • 8.12
      MCQs for “Python Dictionary View Objects
      10 Minutes4 Questions
    • 8.13
      Python – Loop Dictionaries
    • 8.14
      MCQs for “Python – Loop Dictionaries”
      10 Minutes4 Questions
    • 8.15
      Python – Copy Dictionaries
    • 8.16
      MCQs for “Python – Copy Dictionaries”
      10 Minutes4 Questions
    • 8.17
      Python – Nested Dictionaries
    • 8.18
      MCQs for “Python – Nested Dictionaries”
      10 Minutes4 Questions
    • 8.19
      Python – Dictionary Methods
    • 8.20
      MCQs for “Python – Dictionary Methods”
      10 Minutes4 Questions
  • Python Arrays
    20
    • 9.1
      Python – Arrays
    • 9.2
      MCQs for “Python – Arrays”
      10 Minutes4 Questions
    • 9.3
      Python – Access Array Items
    • 9.4
      MCQs for “Python – Access Array Items
      10 Minutes4 Questions
    • 9.5
      Python – Add Array Items
    • 9.6
      MCQs for “Python – Add Array Items”
      10 Minutes4 Questions
    • 9.7
      Python – Remove Array Items
    • 9.8
      MCQs for “Python – Remove Array Items”
      10 Minutes4 Questions
    • 9.10
      Python – Loop Arrays
    • 9.11
      MCQs for “Python – Loop Arrays”
      10 Minutes4 Questions
    • 9.12
      Python – Copy Arrays
    • 9.13
      MCQs for “Python – Copy Arrays”
      10 Minutes5 Questions
    • 9.14
      Python – Reverse Arrays
    • 9.15
      MCQs for “Python – Reverse Arrays”
      10 Minutes4 Questions
    • 9.16
      Python – Sort Arrays
    • 9.17
      MCQs for “Python – Sort Arrays”
      10 Minutes4 Questions
    • 9.18
      Python – Join Arrays
    • 9.19
      MCQs for “Python – Join Arrays”
      10 Minutes4 Questions
    • 9.20
      Python – Array Methods
    • 9.21
      MCQs for “Python – Array Methods”
      10 Minutes4 Questions
  • Python File Handling
    16
    • 10.1
      Python – File Handling
    • 10.2
      MCQs for “Python – File Handling”
      10 Minutes4 Questions
    • 10.3
      Python – Write to File
    • 10.4
      MCQs for “Python – Write to File”
      10 Minutes4 Questions
    • 10.5
      Python – Read Files
    • 10.6
      MCQs for “Python – Read Files”
      10 Minutes4 Questions
    • 10.7
      Python – Renaming and Deleting Files
    • 10.8
      MCQs for “Python – Renaming and Deleting Files”
      10 Minutes4 Questions
    • 10.9
      Python – Directories
    • 10.10
      MCQs for “Python – Directories”
      10 Minutes4 Questions
    • 10.11
      Python – File Methods
    • 10.12
      MCQs for “Python – File Methods”
      10 Minutes4 Questions
    • 10.13
      Python OS File/Directory Methods
    • 10.14
      MCQs for “Python OS File/Directory Methods”
      10 Minutes4 Questions
    • 10.15
      Python OS.Path Methods
    • 10.16
      MCQs for “Python OS.Path Methods”
      10 Minutes4 Questions
  • Object Oriented Programming
    46
    • 11.1
      Python – OOPs Concepts
    • 11.2
      MCQs for “Python – OOP Concepts”
      10 Minutes4 Questions
    • 11.3
      Python – Classes and Objects
    • 11.4
      MCQs for “Python – Classes and Objects”
      10 Minutes4 Questions
    • 11.5
      Python – Class Attributes
    • 11.6
      MCQs for “Python – Class Attributes”
      10 Minutes4 Questions
    • 11.7
      Python – Class Methods
    • 11.8
      MCQs for “Python – Class Methods”
      10 Minutes4 Questions
    • 11.9
      Python – Static Methods
    • 11.10
      MCQs for “Python – Static Methods”
      10 Minutes4 Questions
    • 11.11
      Python – Constructors
    • 11.12
      MCQs for “Python – Constructors”
      10 Minutes4 Questions
    • 11.13
      Python – Access Modifiers
    • 11.14
      MCQs for “Python – Access Modifiers”
      10 Minutes4 Questions
    • 11.15
      Python – Inheritance
    • 11.16
      MCQs for “Python – Inheritance”
      10 Minutes4 Questions
    • 11.17
      Python – Polymorphism
    • 11.18
      MCQs for “Python – Polymorphism”
      10 Minutes4 Questions
    • 11.19
      Python – Method Overriding
    • 11.20
      MCQs for “Python – Method Overriding”
      10 Minutes4 Questions
    • 11.21
      Python – Method Overloading
    • 11.22
      MCQs for “Python – Method Overloading”
      10 Minutes4 Questions
    • 11.23
      Python – Dynamic Binding
    • 11.24
      MCQs for “Python – Dynamic Binding”
      10 Minutes4 Questions
    • 11.25
      Python – Dynamic Typing
    • 11.26
      MCQs for “Python – Dynamic Typing”
      10 Minutes4 Questions
    • 11.27
      Python – Abstraction
    • 11.28
      MCQs for “Python – Abstraction”
      10 Minutes4 Questions
    • 11.29
      Python – Encapsulation
    • 11.30
      MCQs for “Python – Encapsulation”
      10 Minutes4 Questions
    • 11.31
      Python – Interfaces
    • 11.32
      MCQs for “Python – Interfaces”
      10 Minutes4 Questions
    • 11.33
      Python – Packages
    • 11.34
      MCQs for “Python – Packages”
      10 Minutes4 Questions
    • 11.35
      Python – Inner Classes
    • 11.36
      MCQs for “Python – Inner Classes”
      10 Minutes4 Questions
    • 11.37
      Python – Anonymous Class and Objects
    • 11.38
      MCQs for “Python – Anonymous Class and Objects”
      10 Minutes4 Questions
    • 11.39
      Python – Singleton Class
    • 11.40
      MCQs for “Python – Singleton Class”
      10 Minutes4 Questions
    • 11.41
      Python – Wrapper Classes
    • 11.42
      MCQs for “Python – Wrapper Classes”
      10 Minutes4 Questions
    • 11.43
      Python – Enums
    • 11.44
      MCQs for “Python – Enums”
      10 Minutes4 Questions
    • 11.45
      Python – Reflection
    • 11.46
      MCQs for “Python – Reflection”
      10 Minutes4 Questions
  • Python Errors & Exceptions
    22
    • 12.1
      Python – Syntax Errors
    • 12.2
      MCQs for “Python – Syntax Errors”
      10 Minutes4 Questions
    • 12.3
      Python – Exceptions
    • 12.4
      MCQs for “Python – Exceptions Handling”
      10 Minutes4 Questions
    • 12.5
      Python – The try-except Block
    • 12.6
      MCQs for “Python Try-Except Block”
      10 Minutes4 Questions
    • 12.7
      Python – The try-finally Block
    • 12.8
      MCQs for “Python Try-Finally Block”
      10 Minutes4 Questions
    • 12.9
      Python – Raising Exceptions
    • 12.10
      MCQs for “Raising Exceptions in Python”
      10 Minutes4 Questions
    • 12.11
      Python – Exception Chaining
    • 12.12
      MCQs for “Exception Chaining”
      10 Minutes4 Questions
    • 12.13
      Python – Nested try Block
    • 12.14
      MCQs for “Nested try Block in Python”
      10 Minutes4 Questions
    • 12.15
      Python – User-Defined Exceptions
    • 12.16
      MCQs for “User-Defined Exceptions in Python”
      10 Minutes4 Questions
    • 12.17
      Python – Logging
    • 12.18
      MCQs for “Logging in Python”
      10 Minutes4 Questions
    • 12.19
      Python – Assertions
    • 12.20
      MCQs for “Assertions in Python”
      10 Minutes4 Questions
    • 12.21
      Python – Built-in Exceptions
    • 12.22
      MCQs for “Python – Built-in Exceptions”
      10 Minutes4 Questions
  • Python Multithreading
    24
    • 13.1
      Python – Multithreading
    • 13.2
      MCQs for “Multithreading in Python”
      10 Minutes4 Questions
    • 13.3
      Python – Thread Life cycle
    • 13.4
      MCQs for “Thread Life Cycle in Python”
      10 Minutes4 Questions
    • 13.5
      Python – Creating a Thread
    • 13.6
      MCQs for “Creating Threads in Python”
      10 Minutes4 Questions
    • 13.7
      Python – Starting a Thread
    • 13.8
      MCQs for “Starting a Thread in Python”
      10 Minutes4 Questions
    • 13.9
      Python – Joining the Threads
    • 13.10
      MCQs for “Joining the Threads in Python”
      10 Minutes4 Questions
    • 13.11
      Python – Naming the Threads
    • 13.12
      MCQs for “Naming the Threads in Python”
      10 Minutes4 Questions
    • 13.13
      Python – Thread Scheduling
    • 13.14
      MCQs for “Thread Scheduling in Python”
      10 Minutes4 Questions
    • 13.15
      Python – Thread Pools
    • 13.16
      MCQs for “Thread Pool in Python”
      10 Minutes4 Questions
    • 13.17
      Python – Main Thread
    • 13.18
      MCQs for “Main Thread in Python”
      10 Minutes4 Questions
    • 13.19
      Python – Thread Priority
    • 13.20
      MCQs for “Thread Priority in Python”
      10 Minutes4 Questions
    • 13.21
      Python – Daemon Threads
    • 13.22
      MCQs for “Daemon Threads in Python”
      10 Minutes4 Questions
    • 13.23
      Python – Synchronizing Threads
    • 13.24
      MCQs for “Synchronizing Threads in Python”
      10 Minutes4 Questions
  • Python Synchronization
    6
    • 14.1
      Python – Inter-Thread Communication
    • 14.2
      MCQs for “Inter-Thread Communication in Python”
      10 Minutes4 Questions
    • 14.3
      Python – Thread Deadlock
    • 14.4
      MCQs for “Deadlock in Python”
      10 Minutes4 Questions
    • 14.5
      Python – Interrupting a Thread
    • 14.6
      MCQs for “Interrupting a Thread in Python”
      10 Minutes4 Questions
  • Python Networking
    8
    • 15.1
      Python – Network Programming
    • 15.2
      MCQs for “Networking and Interprocess Communication in Python”
      10 Minutes4 Questions
    • 15.3
      Python – Socket Programming
    • 15.4
      MCQs for “Python Socket Programming”
      10 Minutes4 Questions
    • 15.5
      Python – URL Processing
    • 15.6
      MCQs for “Working with URLs in Python using urllib”
      10 Minutes4 Questions
    • 15.7
      Python – Generics
    • 15.8
      MCQs for “Generics in Python”
      10 Minutes4 Questions

Python – Remove Dictionary Items

Remove Dictionary Items in Python

Table of Contents

Toggle
  • Remove Dictionary Items in Python
    • Table of Contents
    • Remove Dictionary Items in Python
    • Remove Dictionary Items Using del Keyword
    • Remove Dictionary Items Using pop() Method
    • Remove Dictionary Items Using popitem() Method
    • Remove Dictionary Items Using clear() Method
    • Remove Dictionary Items Using Dictionary Comprehension

Table of Contents

  • Remove Dictionary Items in Python
  • Remove Dictionary Items Using del Keyword
  • Remove Dictionary Items Using pop() Method
  • Remove Dictionary Items Using popitem() Method
  • Remove Dictionary Items Using clear() Method
  • Remove Dictionary Items Using Dictionary Comprehension

Remove Dictionary Items in Python

Removing dictionary items in Python refers to deleting key-value pairs from an existing dictionary. Dictionaries are mutable data structures that hold pairs of keys and their associated values. Each key acts as a unique identifier, mapping to a specific value within the dictionary.

Removing items from a dictionary allows you to eliminate unnecessary or unwanted data from the dictionary, thereby reducing its size and modifying its content.

We can remove dictionary items in Python using various ways such as:

  • Using the del keyword
  • Using the pop() method
  • Using the popitem() method
  • Using the clear() method
  • Using dictionary comprehension

Remove Dictionary Items Using del Keyword

The del keyword in Python is used to delete objects. In the context of dictionaries, it is used to remove an item or a slice of items from the dictionary, based on the specified key(s).

We can remove dictionary items using the del keyword by specifying the key of the item we want to remove. This will delete the key-value pair associated with the specified key from the dictionary.

Example 1

numbers = {10:"Ten", 20:"Twenty", 30:"Thirty",40:"Forty"}
print("numbers dictionary before delete operation: \n", numbers)
del numbers[20]
print("numbers dictionary after delete operation: \n", numbers)

Output:

numbers dictionary before delete operation:
{10: 'Ten', 20: 'Twenty', 30: 'Thirty', 40: 'Forty'}
numbers dictionary after delete operation:
{10: 'Ten', 30: 'Thirty', 40: 'Forty'}

Example 2

numbers = {10:"Ten", 20:"Twenty", 30:"Thirty",40:"Forty"}
print("numbers dictionary before delete operation: \n", numbers)
del numbers
print("numbers dictionary after delete operation: \n", numbers)

Output:

numbers dictionary before delete operation:
{10: 'Ten', 20: 'Twenty', 30: 'Thirty', 40: 'Forty'}
Traceback (most recent call last):
  File "C:\Users\mlath\examples\main.py", line 5, in 
    print("numbers dictionary after delete operation: \n", numbers)
NameError: name 'numbers' is not defined

Remove Dictionary Items Using pop() Method

The pop() method in Python is used to remove a specified key from a dictionary and return the corresponding value. If the specified key is not found, it can optionally return a default value instead of raising a KeyError.

Example

numbers = {10:"Ten", 20:"Twenty", 30:"Thirty",40:"Forty"}
print("numbers dictionary before pop operation: \n", numbers)
val = numbers.pop(20)
print("numbers dictionary after pop operation: \n", numbers)
print("Value popped: ", val)

Output:

numbers dictionary before pop operation:
{10: 'Ten', 20: 'Twenty', 30: 'Thirty', 40: 'Forty'}
numbers dictionary after pop operation:
{10: 'Ten', 30: 'Thirty', 40: 'Forty'}
Value popped:  Twenty

Remove Dictionary Items Using popitem() Method

The popitem() method in Python is used to remove and return the last key-value pair from a dictionary.

Example

numbers = {10:"Ten", 20:"Twenty", 30:"Thirty",40:"Forty"}
print("numbers dictionary before pop operation: \n", numbers)
val = numbers.popitem()
print("numbers dictionary after pop operation: \n", numbers)
print("Value popped: ", val)

Output:

numbers dictionary before pop operation:
{10: 'Ten', 20: 'Twenty', 30: 'Thirty', 40: 'Forty'}
numbers dictionary after pop operation:
{10: 'Ten', 20: 'Twenty', 30: 'Thirty'}
Value popped:  (40, 'Forty')

Remove Dictionary Items Using clear() Method

The clear() method in Python is used to remove all items from the dictionary, leaving it empty.

Example

numbers = {10:"Ten", 20:"Twenty", 30:"Thirty",40:"Forty"}
print("numbers dictionary before clear method: \n", numbers)
numbers.clear()
print("numbers dictionary after clear method: \n", numbers)

Output:

numbers dictionary before clear method:
{10: 'Ten', 20: 'Twenty', 30: 'Thirty', 40: 'Forty'}
numbers dictionary after clear method:
{}

Remove Dictionary Items Using Dictionary Comprehension

Dictionary comprehension can be used to filter out items from a dictionary based on specific conditions. This technique is often useful for removing multiple dictionary items based on criteria without manually popping them one by one.

Example

student_info = {
    "name": "Alice",
    "age": 21,
    "major": "Computer Science"
}
keys_to_remove = ["age", "major"]
for key in keys_to_remove:
    student_info.pop(key, None)
print(student_info)

Output:

{'name': 'Alice'}
MCQ Add Dictionary Items
Prev
MCQ Remove Dictionary Items
Next

Modal title

Main Content