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
Articles by Vikram Chiluka
Page 21 of 22
How to write a function to get the time spent in each function in Python?
In Python, measuring the execution time of functions is essential for performance analysis and optimization. Python provides several built-in modules like time and datetime to measure function execution time effectively. Using time.time() Method Using time.process_time() Function Using datetime.now() Function Creating a Timer Decorator Function Using time.time() Method The time.time() method returns the current time in seconds since January 1, 1970 (Unix epoch). This method measures wall-clock time, including time spent waiting for I/O operations or system delays. To ...
Read MoreHow to sort the objects in a list in Python?
In Python, a list is an ordered sequence that can hold several object types such as integer, character, or float. In other programming languages, a list is equivalent to an array. Square brackets are used to denote it, and a comma (, ) is used to divide two items in the list. In this article, we will show you how to sort the objects and elements in a list using Python. Below are the different methods to accomplish this task − Using sort() method Using sorted() method Assume we have taken a list containing some ...
Read MoreHow to check if a list is empty in Python?
In Python, a list is an ordered sequence that can hold several object types, such as integers, characters, or floats. In this article, we will show you how to check if the given input list is empty or not using Python. Below are the 5 methods to accomplish this task ? Using not operator Using len() function By Comparing with an Empty List Using __len__() Method Using NumPy Module Using the NOT Operator In Python, empty lists evaluate to False in boolean context. The not operator provides the most Pythonic way to check for ...
Read MoreHow I can convert a Python Tuple into Dictionary?
The Python tuple elements are enclosed inside the parentheses, while dictionary elements are present in the form of a key-value pair and are enclosed between curly brackets. In this article, we will show you how to convert a Python tuple into a dictionary. The following are the methods to convert a tuple into a dictionary − Using dict() Function Using Dictionary Comprehension and enumerate() Function ...
Read MoreHow does Python compare to PHP in ease of learning for new programmers?
When comparing Python and PHP for new programmers, both languages offer unique advantages, but they differ significantly in learning curve, syntax clarity, and career opportunities. Let's explore how these languages compare for beginners. Python: Beginner-Friendly Design Python is widely regarded as an excellent first programming language due to its emphasis on readability and clean coding practices. Key Advantages for Beginners Python enforces proper coding techniques through mandatory indentation, making code naturally readable and well-structured. It's strongly typed, preventing common beginner mistakes like mixing incompatible data types. The language's syntax is intuitive and closely resembles natural English. ...
Read MoreHow to round down to 2 decimals a float using Python?
In this article, we will show you how to round off a floating number upto 2 decimals in python. Below are the various methods to accomplish this task: Using round() function Using format() function Using Decimal Module Using ceil() function Using round() function The round() function gives a floating point number with a specified number of decimals which is the rounded version of the specified number. The function will return the nearest integer because the default value for the number of decimals is 0. Syntax round(number, digits) Parameters number(required)- a number that should be rounded digits(optional)- ...
Read MoreHow to perform square root without using math module in Python?
In this article, we will show you how to perform square root without using a math module in Python. Below are the various methods to accomplish this task: Using exponential operator ** Using Mathematical Logic Using exponential operator ** Without using the math module, the simplest approach to find the square root of a number in Python is to use the built-in exponential operator ** (It is an exponent operator because it calculates the power of the first operand to the power of the second operand). Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired ...
Read MoreWhat is correct name of * operator available in Python?
In this article, we will explain the correct name of the * operator available in python. In Python, you'll encounter the symbols * and ** used frequently. Many Python programmers, especially those at the intermediate level, are confused by the asterisk (*) character in Python. The *args argument is called the "variable positional parameter" and **kwargs is the "variable keyword parameter". The * and ** arguments just unpack their respective data structures.Using Asterisk ( * ) Operator in Multiplication Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Create two variables and ...
Read MoreHow can I represent an infinite number in Python?
In this article, we will show you how to represent an infinite number in python. Infinity is an undefined number that can be either positive or negative. A number is used to represent infinity; the sum of two numeric values may be a numeric but distinct pattern; it may have a negative or positive value. All arithmetic operations on an infinite value, whether sum, subtraction, multiplication or any other operation, always result in an infinite number. In the field of computer science, infinity is commonly used to evaluate and optimize algorithms that do calculations on a huge scale. Infinity in ...
Read MoreHow to Find HCF or GCD using Python?
In this article, we will show you how to find the HCF (Highest Common Factor) or GCD (Greatest Common Factor) in Python. Below are the various methods to accomplish this task: Using For Loop Using Euclidean Algorithm Using While Loop Using Recursion(Naive method) Handling Negative Numbers in HCF What is H.C.F. or G.C.D? The largest positive integer that perfectly divides the two given numbers is known as the highest common factor (H.C.F.) or greatest common divisor (G.C.D.). Example - The HCF of 12 and 14, is 2. Using For Loop Algorithm (Steps) Following are the Algorithm/steps to be followed to ...
Read More