Sarika Singh has Published 118 Articles

How to use variable-length arguments in a function in Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 12:51:57

19K+ Views

As the name implies, an argument with a variable length can take on a variety of values. You define a variable argument using a '*', for example *args, to show that the function can take a variable number of arguments. Observations on Python's variable-length arguments are as follows - ... Read More

What is the difference between attributes and properties in python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 12:50:18

7K+ Views

In Python, everything is an object. And every object has attributes and methods, or functions. Attributes are described by data variables, for example like name, age, height, etc.Properties  Properties are a special kind of attributes that have getter, setter, and delete methods like __get__, __set__, and __delete__ methods. A property ... Read More

How to produce documentation for Python functions?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 12:44:11

517 Views

In Python, documenting your functions is an important step that helps others understand what your code does, what inputs it expects, and what it returns. Python provides a built-in way to write documentation using docstrings. By producing good documentation, you can make your code more readable and usable in larger ... Read More

How to catch a python exception in a list comprehension?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 17:48:47

2K+ Views

Before we understand how to catch a Python exception in a list comprehension, let us first learn what a list comprehension is.Python List Comprehension List comprehension is a statement that allows you to create a list and execute a for loop, all in a single sentence.This also allows the lists ... Read More

How to handle a python exception within a loop?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 17:11:18

14K+ Views

The looping technique in Python transforms complex problems into simple ones. It allows us to change the flow of the program so that instead of writing the same code over and over, we can repeat it a limited number of times until a certain condition is satisfied. For example, ... Read More

How to call a function with argument list in Python?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 17:09:34

4K+ Views

The purpose of a function is to perform a specific task using code blocks. In programming, functions save time by eliminating unnecessary and excessive copying and pasting of code. Hence, a function will be of great use if there is a common action that needs to be performed in different ... Read More

How to ignore an exception and proceed in Python?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 17:07:46

33K+ Views

An exception is an unexpected error or event that occurs during the execution of program. The difference between an error and an exception in a program is that, when an exception is encountered, the program deflects from its original course of execution whereas when an error occurs, the program is ... Read More

How to pass keyword parameters to a function in Python?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 17:02:05

6K+ Views

In Python, functions are usually called by passing none, one or more arguments to it. There are two types of arguments that can be used - Positional arguments ... Read More

How to print the Python Exception/Error Hierarchy?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 16:52:30

3K+ Views

We will learn about what an exception is before learning how to print Python exceptions. An exception occurs when a program fails to execute in the direction it was intended to be. Python throws exceptions when unexpected errors or events occur. It is common for exceptions to be both valid ... Read More

How to set default parameter values to a function in Python?

Sarika Singh

Sarika Singh

Updated on 14-May-2025 15:57:09

14K+ Views

Python functions are used to implement logic that you may want to reuse in multiple places in your code. These functions accept input parameters called arguments. You can also assign default values to these parameters. If you do not pass any value for a parameter during a function call, the ... Read More

Advertisements