
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10406 Articles for Python

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 decorator in Python provides getter/setter access to an attribute. You can define getters, setters, and delete methods with the property function. If you just want the read property, there is also a @property decorator you can add above your method. Example This example shows how to use the @property decorator ... Read More
3K+ Views
Functions accept arguments that can contain data. The function name is followed by parenthesis that list the arguments. Simply separate each argument with a comma to add as many as you like. As the name implies, mandatory arguments are those that must be given to the function at the time of the function call. Failure to do so will lead to a mistake. Simply put, default function parameters are the exact opposite of required arguments. As we previously saw, while declaring the function, we give the function parameters a default value in the case of default arguments. The function automatically ... Read More

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 function names can consist of the following characters - Letters (A–Z, a–z) Digits (0–9) — but not at the beginning Underscores (_) — often used to separate words Function names must follow these rules - Must start with a letter or underscore Cannot start with a digit ... Read More

357 Views
When you write tests in Python, it is important to make sure that your function raises the correct exception for invalid input or unexpected conditions. This helps to confirm that your code handles errors properly. You can test exceptions using the following ways in python − Using the try-except blocks manually Using the unittest module Using the pytest module Using try-except Block One of the basic ways to test for exceptions is by manually using a try-except block. This allows you to execute code and catch any exceptions that occur. If the function doesn't raise the ... Read More

426 Views
In Python, you may notice that code runs faster when it is placed inside a function rather than running directly in the top-level script (global scope). This is due to how Python manages variable lookups and optimizes execution inside functions. Functions have their own local scope, which is much faster to access compared to the global scope. Also, Python internally applies several optimizations when it detects function boundaries. Reasons for Faster Execution in Functions Here are the main reasons why Python code executes faster inside a function - Local Variable Access: Local variables are stored in a fixed-size array, ... Read More

480 Views
In Python, scoping rules define where you can access or modify a variable in your code. It is important to understand these rules because using a variable in the wrong place can cause errors or unexpected results. Python follows a specific order to find a variable, called the LEGB rule. This rule looks for variables in the following order - Local: First inside the function. Enclosing: Then, in any enclosing function. Global: Then, in the global scope. Built-in: Finally, in Python's built-in names. What is the LEGB Rule? The LEGB rule tells Python how to search for variable ... Read More

377 Views
MATLAB has a built-in feature called Python integration that allows you to call Python functions directly from your MATLAB code. You don't need to install any extra tools or software as long as Python is already installed on your system; MATLAB can work with it. With Python integration, you can call Python functions, use Python libraries, and interact with Python objects right inside MATLAB. To do this, simply use the py. prefix before the name of the Python function or module. To make this work smoothly, make sure your Python environment is properly set up. Also, the Python ... Read More

222 Views
In Python, you can store a function as a text string in a SQLite database using the sqlite3 module. You cannot run the function directly from the database, but you can retrieve the code later and execute it using Python's exec() or eval() functions. This is helpful when you want to store or update function logic, like in code editors, plugins, or apps that run user-created scripts. Using sqlite3 and exec() Function The sqlite3 module is used to create and work with SQLite databases in Python. The exec() function can run Python code that is stored as a string, including ... Read More

10K+ Views
We can pass a JSON object as a parameter to a Python function using the json.loads() method. we can also convert the JSON string into a Python dictionary or list, which depends on its structure. Once converted, the data can be used just like any other dictionary or list in Python. JSON Object Consider a JSON object to pass to a python function. We will use it further in this article - { "name":"Rupert", "age": 25, "desig":"developer" } Using json.loads() Function Before passing a JSON object as a parameter ... Read More

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 APIs, sending data in web responses, or saving organized data in files. Using json.dumps() Function The json.dumps function is used to convert a Python object (like a dictionary or list) into a JSON-formatted string. Syntax Following is its basic syntax - json.dumps(python_object) Where python_object is usually a dictionary or list ... Read More