Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Searching multiple columns for a row match in MySQL
To search multiple columns for a row match in MySQL, you can use the UNION operator. UNION combines the result sets of two or more SELECT statements into a single result, automatically removing duplicate rows. This is useful when you want to search different columns for different criteria and merge the results together. Creating the Demo Table Let us first create a table and insert some records − CREATE TABLE DemoTable645 ( Id INT, FirstName VARCHAR(100) ); INSERT INTO DemoTable645 VALUES (100, 'Chris'); INSERT INTO DemoTable645 VALUES (101, 'Robert'); INSERT INTO DemoTable645 ...
Read MoreDifference between attributes and properties in python?
In Python, everything is an object, and every object has attributes and methods. Attributes are data variables that describe the object (such as name, age, or height), while properties are a special kind of attribute that use getter, setter, and deleter methods to control access to the underlying data. Attributes in Python Attributes are variables that belong to an object. They are usually defined in the __init__ method and accessed using dot notation ? Example class Dog: def __init__(self, name, age): self.name = name ...
Read MoreSaving Python functions in a Sqlite table
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 MoreWhy Python functions are hashable?
An object in Python is hashable if it has a hash value that remains the same during its lifetime. It must have a __hash__() method and be comparable to other objects via __eq__(). If two hashable objects are equal when compared, they have the same hash value. Being hashable makes an object usable as a dictionary key and a set member, since these data structures use hash values internally. All immutable built-in objects in Python are hashable. Mutable containers like lists and dictionaries are not hashable, while immutable containers like tuples are. Objects that are instances of user-defined classes are ...
Read MoreThe return Statement in Python
The return statement in Python is used to send a value back from a function to its caller and exit the function. Since everything in Python is an object, the return value can be any object such as numeric types (int, float), collections (list, tuple, dict), or even other functions. Key features of the return statement − It cannot be used outside a function. Any code written after a return statement within the same block is dead code and will never be executed. If no value is specified, None is returned implicitly. Syntax def some_function(parameters): ...
Read MoreWhat is an anonymous function in Python?
Anonymous Function in Python An anonymous function is a function which doesn't have a name. We can return a value from an anonymous function, call it at the time of creation or, assign it to a variable. Instead of using the def keyword, which is used for regular functions, anonymous functions are defined using the lambda keyword. Hence, they are commonly referred to as lambda functions. Syntax Following is the syntax to create anonymous functions using the lambda keyword - lambda [args] : expression Although a lambda function can have only one expression, it can have any number ...
Read MoreHow to call Python module from command line?
To call a Python module from the command line, you can use the python command followed by flags like -m or -c, or run the script file directly. This article covers the most common approaches with practical examples. Running a Module with python -m The -m flag tells Python to run a module by its module name (without the .py extension). Python searches sys.path for the module and executes its __main__ block − ~$ python -m module_name For example, to run the built-in json.tool module for formatting JSON − ~$ echo '{"name":"Alice"}' | python -m json.tool { ...
Read MoreHow to run Python functions from command line?
To run Python functions from the command line, you save the function in a .py file and then invoke it using the Python interpreter. There are several approaches − using sys.argv, the -c flag, or the argparse module. Using sys.argv with __name__ Guard The most common approach is to use sys.argv to read command-line arguments and the if __name__ == "__main__" guard to call your function when the script is executed directly. The first item in sys.argv is the script name, and subsequent items are the arguments passed. Note that all command-line arguments are received as strings, so you must ...
Read MoreAre Python functions objects?
Yes, Python functions are full objects. Python creates function objects when you use a def statement or a lambda expression. Like any other object, functions can be assigned to variables, passed as arguments, returned from other functions, and even have custom attributes. Functions Have a Type and Support Attributes Since functions are objects, they have a type (function) and you can assign custom attributes to them ? Example def foo(): pass foo.score = 20 print(type(foo)) print(foo.score) print(type(lambda x: x)) The output of the above code is ? 20 ...
Read MoreHow can a Python function return a function?
In Python, functions are treated as first-class objects, which means that all functions in Python are treated like any other object or variable. You can assign a function to a variable, pass it as an argument to another function, return it from a function, or even store it in data structures like lists. One very useful feature in Python is that a function can return another function. This means you can define a function inside another function and return it as a result. This is used in advanced programming concepts like closures, decorators, and higher-order functions. Returning a Simple Function ...
Read More