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
-
Economics & Finance
Server Side Programming Articles
Found 21,091 articles
How can a Python function return a function?
In Python, functions are treated as first-class objects, which means 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. Syntax Following ...
Read MoreWhat are Python function attributes?
In Python, everything is an object, and functions are no exception. Since functions are objects, they can have attributes — custom data attached to them, just like attributes on a class instance. This allows you to store metadata, counters, configuration, or any arbitrary data directly on a function. Function attributes are different from function parameters. Parameters are inputs passed during a function call, while attributes are persistent data stored on the function object itself. Syntax You can set and access function attributes using the dot (.) operator, or using setattr() and getattr() built-in functions − ...
Read MoreC/C++ Ternary Operator
The ternary operator (?:) in C/C++ is a shorthand for an if-else statement. It is the only operator in C/C++ that takes three operands, which is why it is called "ternary". Syntax (expression-1) ? expression-2 : expression-3 This operator returns one of two values depending on the result of an expression. If expression-1 evaluates to Boolean true, then expression-2 is evaluated and its value is returned as the final result. Otherwise, expression-3 is evaluated and its value is returned. Ternary Operator Flow condition ? ...
Read MoreAnti Clockwise spiral traversal of a binary tree?
Here we will see one interesting problem. We have a binary tree and we have to traverse it in an anti-clockwise manner. The traversal alternates between printing levels from right-to-left (starting from the top) and left-to-right (starting from the bottom), creating a spiral-like anti-clockwise pattern. For the binary tree shown below, the anti-clockwise traversal sequence is − 1, 8, 9, 10, 11, 12, 13, 14, 15, 3, 2, 4, 5, 6, 7 Binary Tree — Anti-Clockwise Traversal ...
Read MoreA comma operator question in C/C++ ?
The comma (, ) in C/C++ programming language has two contexts − As a separator − Used to separate variable declarations, function arguments, and initializer values. In this context, the comma is not an operator. As an operator − The comma operator is a binary operator that evaluates the first expression, discards its result, then evaluates and returns the value of the second expression. This operator has the lowest precedence of all C/C++ operators — even lower than the assignment operator. Syntax result = (expr1, expr2); // ...
Read MoreDifference between %p and %x in C/C++
Here we will see what are the differences between %p and %x in C or C++. The %p format specifier is used to print pointer values (memory addresses), while %x is used to print unsigned integers in hexadecimal format. Though pointers can also be displayed using %u or %x, the correct and portable way to print a pointer is %p. The visible difference is that %p prints with leading zeros and is platform-width aware (16 hex digits on 64-bit systems, 8 on 32-bit), while %x prints only the significant digits without padding. Syntax printf("%p", pointer); ...
Read MoreWhy are global and static variables initialized to their default values in C/C++?
Global and static variables are initialized to their default values because it is mandated by the C and C++ standards. The compiler assigns zero at compile time, and it costs nothing extra to do so. Both static and global variables behave the same way in the generated object code — they are allocated in the .bss segment (Block Started by Symbol), and when the program is loaded into memory, the OS zeroes out this entire segment automatically. In contrast, local (automatic) variables are stored on the stack and are not initialized — they contain whatever garbage value was previously ...
Read MoreWhich one is the Python module to obfuscate javascript?
You can use the jsmin module to minimize and obfuscate JavaScript code using Python. Minification removes whitespace, comments, and unnecessary characters from JavaScript files, reducing file size without changing functionality. Installing jsmin Install jsmin using pip − $ pip install jsmin Syntax Following is the basic syntax for using jsmin in Python − from jsmin import jsmin minified_code = jsmin(javascript_string) The jsmin() function takes a JavaScript source string as input and returns the minified version as a string. Minifying a JavaScript File To use jsmin in ...
Read MoreC# Program to Merge Two Hashtable Collections
The Hashtable collection in C# stores key-value pairs where each element is a DictionaryEntry object. The key is unique and non-null, used to access elements in the hashtable. Values can be null or duplicated, but the combination of key-value pairs must be unique. Since the Hashtable class doesn't provide a built-in merge method, we need to implement our own approach by iterating through one hashtable and adding its elements to another while checking for duplicate keys. Syntax Following is the syntax for creating and populating a Hashtable − Hashtable hashtableName = new Hashtable(); hashtableName.Add(key, value); ...
Read MoreHow to Get Value from HashTable Collection in C# using Specified Key
A Hashtable is a collection of key-value pairs that provides fast lookup by key. In C#, you can retrieve values from a hashtable using the indexer syntax hashtable[key] or by checking if a key exists using the Contains() method. This is essential for accessing specific data when you know the corresponding key. Syntax Following is the syntax for getting a value from a hashtable using a specified key − // Check if key exists if (hashtable.Contains(key)) { object value = hashtable[key]; } // Direct access (may return null if key doesn't exist) ...
Read More