Manually Raising (throwing) an Exception in Python

Problem Statement: How to raise (throw) an exception in Python manually? Using raise to Throw Exception in Python You can decide to throw a specific exception manually if a particular condition arises with the help of the raise keyword. As a good practice, you should raise specific exceptions. In the following example, we will raise … Read more

Parse JSON Data in Python

Problem Formulation Do you have JSON data that you need to parse using a Python script? Let’s have a look at this JSON data – But when you try to parse this file in your script, you get an exception. Frustrating! Isn’t it? Don’t worry. Most probably you have no errors in your script. The … Read more

How to declare an array in Python?

[toc] Have you been wondering – “How to declare an array in Python?” Well, if your answer is yes, then you are at the right place to find your answers; as in this article, we are going to learn about the different ways of declaring an array in Python. Video Walkthrough A Quick Introduction to … Read more

Delete an Element in a Dictionary | Python

[toc] Summary: Use these methods to delete a dictionary element in Python –(1) del dict[‘key’](2) dict.clear(‘key’)(3) Use a dictionary comprehension(4) Use a for loop to eliminate the key Problem: Given a Python dictionary. How to delete an element from the dictionary? Example: A Quick Recap to Python Dictionaries A Python dictionary is a data structure … Read more