Sarika Singh has Published 189 Articles

How to catch SystemExit Exception in Python?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:22:21

3K+ Views

The SystemExit exception in Python is raised when the sys.exit() function is called. It is used to exit the program cleanly. Although this exception is not an error in the traditional sense, it can be caught using a try-except block if needed, especially when you want to prevent a ... Read More

Suggest a cleaner way to handle Python exceptions?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 14:06:23

206 Views

Python uses the try-except block to handle errors during runtime. But as your program grows, handling exceptions can get messy with repeated code or too many nested blocks. Using cleaner methods for exception handling can reduce duplication, and make your code easier to manage. In this article, we explore ... Read More

How to write custom Python Exceptions with Error Codes and Error Messages?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 14:03:21

1K+ Views

Custom exceptions in Python allow you to create meaningful error types that fit your application's needs. By adding error codes and error messages to custom exceptions, you can provide structured (organized) information when errors occur. Although Python has many built-in exceptions, custom exceptions are well-suited to explain specific problems in ... Read More

How to print characters from a string starting from 3rd to 5th in Python?

Sarika Singh

Sarika Singh

Updated on 29-May-2025 03:32:32

10K+ Views

Python uses arrays of bytes called strings to represent Unicode characters. In Python, string indexing ranges from 0 to n-1, where n is the length of the string. In a string of size n, the characters can be retrieved from 0 to n-1. For Example, we can index the string ... Read More

How to create a tar file using Python?

Sarika Singh

Sarika Singh

Updated on 29-May-2025 03:23:40

14K+ Views

TAR stands for Tape Archive Files. The Tar files are the archive files which allows us to store numerous files in a single file. A Open-source software is distributed using tar files. Tar files typically end in .tar later they can be compressed using tools such as gzip which have ... Read More

How to create a zip file using Python?

Sarika Singh

Sarika Singh

Updated on 28-May-2025 14:44:07

70K+ Views

ZIP is a widely used file format that compresses one or more files into a single archive file. This file format helps to reduce storage space and simplifies sharing or save backup of large data files. ZIP archives usually have a .zip file extension and are commonly used across different ... Read More

How to catch IndentationError Exception in python?

Sarika Singh

Sarika Singh

Updated on 27-May-2025 17:25:30

1K+ Views

Python uses indentation to define blocks of code instead of curly braces or keywords. If the indentation is not correct, Python raises an IndentationError. In this article, you will learn how to catch and handle IndentationError in Python using various approaches. An IndentationError in Python occurs when the indentation rules ... Read More

How to catch TypeError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 27-May-2025 17:19:55

694 Views

A TypeError occurs in Python when we perform an operation on an object of an inappropriate type. For example, adding a string to an integer or calling a non-callable object. In this article, you will learn how to catch and handle TypeError exceptions using different methods in Python. TypeError is ... Read More

How to catch EnvironmentError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 27-May-2025 17:17:10

530 Views

In Python, the EnvironmentError occurs when errors related to the system's environment, such as file I/O issues or hardware failures, occur. In the latest Python versions (i.e., 3.3+), this exception is the same as OSError. In this article, you will learn how to catch EnvironmentError (or OSError) to handle system-level ... Read More

How to catch LookupError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 27-May-2025 12:11:54

2K+ Views

LookupError in Python is the base class for errors that occur when a lookup using a key or index fails to find the expected value. This includes exceptions like IndexError and KeyError. If any lookup operation fails, a LookupError or one of its subclasses is raised. In this article, you ... Read More

Previous 1 ... 4 5 6 7 8 ... 19 Next
Advertisements