Sarika Singh has Published 137 Articles

How to list non-hidden files and directories in windows using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 15:26:41

2K+ Views

Listing files and directories using Python is a common task in many applications, from file management tools to automated scripts. However, when we are working on the Windows Operating System, the hidden files and folders are marked using specific file attributes, which can clutter the output if not handled properly. ... Read More

What are the allowed characters in Python function names?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 14:20:17

2K+ Views

In Python, function names follow specific rules. A valid function name can only contain certain characters, and it must follow the naming conventions defined in the Python language syntax. Using the correct characters ensures that your code runs without syntax errors and stays readable. Allowed Characters in Function Names Python ... Read More

What is the difference between \'except Exception as e\' and \'except Exception, e\' in Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 14:07:20

1K+ Views

You can handle errors in Python using the try and except blocks. Sometimes, we also want to store the actual exception in a variable to print it or inspect it. This is done using the as keyword in modern Python. But if you have seen older code, you might find ... Read More

How to catch KeyError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 13:54:35

1K+ Views

In Python, a KeyError exception occurs when a dictionary key that does not exist is accessed. This can be avoided by using proper error handling with the try and except blocks, which can catch the error and allow the program to continue running. Understanding KeyError in Python A KeyError is ... Read More

How to return a json object from a Python function?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 13:02:34

2K+ Views

In Python, you need to use the built-in json module to work with JSON data. When you want to return data from a function in JSON format, you can use the json.dumps() function to convert a Python dictionary (or similar object) into a JSON string. This is helpful when making ... Read More

Write down a python function to convert camel case to snake case?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 12:58:38

4K+ Views

Camel case and snake case are ways of writing words together when we are programming. In camel case, we write words together without spaces and we start each new word with a capital letter except for the first word. For example, if we want to write a variable name for ... Read More

How to pass arguments by value in Python function?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 12:56:41

816 Views

In Python, when you pass arguments to a function, they are passed by object reference. This means the function gets a reference (or pointer) to the actual object, not a copy of it. However, how this reference affects the object depends on whether the object is mutable or immutable. ... Read More

How to pass optional parameters to a function in Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 12:55:05

53K+ Views

In Python, you can pass optional parameters to functions, allowing you to call a function with fewer arguments than specified. Optional parameters are useful for providing default values when certain arguments are not provided. Python provides different ways to define optional parameters, including default values, variable-length argument lists, and keyword ... Read More

How to produce documentation for Python functions?

Sarika Singh

Sarika Singh

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

746 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

3K+ 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

Previous 1 ... 6 7 8 9 10 ... 14 Next
Advertisements