Pad the arrays effectively using numpy.pad()

Have you ever come across a situation where you have to add a border to an array or a tensor? Wondering how to go about it? The answer is to use the numpy.pad() The NumPy module has a function named pad() that can be used to pad certain values to the array. In this article, let us discuss the numpy.pad() function and also explore different ways of using it.  What is Padding an Array? Padding means adding some contents to the border of an array. After padding the array, the array would have a different size. But same dimensions. Have … Read more

A Detailed Guide to Remove a Key from the Dictionary in Python

Guide to remove a key from Python dictionary

Python dictionaries are one of the most used data types. These are mutable. That is, we can add new elements or remove the existing elements or change the value of elements in a Python dictionary. To remove the elements from a dictionary, we can use one of the following: pop() popitem() clear() del In today’s article, let’s look at all of these functions with an example. Recommended Reading: How to loop over Python Dictionaries? Method 1: Remove a key from the dictionary using pop() We can use the built-in pop() method to remove a key from a Python dictionary. The … Read more

How to extract div tag and its contents by id using Beautiful Soup ?

Beautiful Soup is an extensively used library in Python for web scraping. This library parses the given webpage and provides the users with an easier way to navigate and access it. When you inspect a webpage and skim through its HTML code, you’ll see that one of the most used tags are the div tags. These tags are used to make a division of the content in the webpage. If you’re scraping a blogging site, it becomes extremely important to learn how to extract the contents from div tags. In today’s article, let’s learn different ways of extracting a div … Read more

How to remove newline from Strings in Python?

In Python, \n  represents a newline character. They are also called line breaks. They are used to indicate the end of the current line. When you’re processing the input files for data cleaning, the first step is to remove the extra spaces and unnecessary newline characters from the lines. At times, you might also want to remove the new line character while printing strings. In this article, we will be addressing the following cases: Removing new line characters from a string. Removing newline characters from a list of strings. Removing newline characters while printing a list of strings. Removing newline … Read more

How does the Python for loop work ?

Loops are one of the first things we learn as programmers. Especially when you are learning Python, trying out a for loop is one of the first things we’ve done. For loops in Python can be used to iterate over the elements of different data types. For example, we can iterate over strings, lists, tuples, dictionaries, and even files. Have you ever wondered how the for loop is so smart to pick letters from strings, elements from a list, or a tuple, and keys and values from a dictionary? In this article, let’s discuss in detail how the Python for … Read more

4 Different ways to loop over Python Dictionaries

Python Dictionaries are used extensively in real-time. If you’re using dictionaries in your program, you should definitely know how to iterate over the dictionary. Although this is simple, there is a lot of confusion in the community. This is because many dictionary functions have changed from Python 2 to Python 3.     In this article, let’s check the different methods used to loop over a dictionary in Python. Note: All the methods described below work for Python versions 3+.   Method 1: Using the dictionary directly Python Dictionaries can be iterated directly. However, it is important to note that, … Read more

Different ways to Check the Python Version

Python is a programming language that is evolving every day. Many times, you will have to print the version number of the Python that is installed on your system. If you want to determine the version of python installed on your system or you want to print the version of the current python installation in your script, read along. Are you new to Python? If you are wondering how to install Python on your Windows system, check out this guide. Understanding Versioning in Python Python versions are in the form of major_version.minor_version.micro_version Bug fixes and simple cosmetic fixes are added … Read more

How to Install Python on Windows 10/11

Python is a widely-used programming language. It is gaining popularity these days as it is easy to learn. Python supports a lot of libraries, so developers can develop the required functionality with ease without having to reinvent the wheel. If you want to install Python 3 on Windows, this guide will help you. Python comes pre-installed on Linux-based operating systems like Ubuntu, MAC, and CentOS. However, we have to download and install Python manually on the Windows OS. There are two versions in Python: Python 2 and Python 3. Both can be installed on any machine free of charge. In … Read more