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 on Trending Technologies
Technical articles with clear explanations and examples
nHow to print out the first character of each list in Python?
A Python list is a built-in, mutable datatype that stores multiple items or elements, separated by commas, within square brackets [ ]. The index of a list in Python starts from 0 up to length-1. We can retrieve/access elements at a particular index as follows ? list_name[index] The given task is to write a Python program that prints the first character of each element in a list. But, before that, let's see some example scenarios: Scenario 1 For example, if our list contains string values, the output should be the first character of ...
Read MoreWhat does \'is\' operator do in Python?
The "is" operator in Python is an identity operator that checks whether two variables refer to the same object in memory. It returns True if both variables point to the same object, and False otherwise. Each object in Python's memory has a unique identification number assigned by the interpreter. The is operator compares these memory addresses using the id() function internally, making it different from the == operator which compares values. Syntax variable1 is variable2 The is operator returns True if both variables reference the same object in memory, False otherwise. Example with ...
Read MoreWhat is "not in" operator in Python?
In Python, the not in membership operator evaluates to True if it does not find a variable in the specified sequence and False otherwise. Syntax element not in sequence Example with Lists Let's check if elements are not present in a list ? a = 10 b = 4 numbers = [1, 2, 3, 4, 5] print(a not in numbers) print(b not in numbers) True False Since a (10) doesn't belong to numbers, a not in numbers returns True. However, b (4) can be found in ...
Read MoreWhat is Python equivalent of the ! operator?
In some languages like C / C++, the "!" symbol is used as a logical NOT operator. !x returns true if x is false, else returns false. The equivalent of this "!" operator in Python is the not keyword, which also returns True if the operand is false and vice versa. Basic Usage with Boolean Values Example with True Value In the following example, the variable operand_X holds a boolean value True. After applying the not operator, it returns False − operand_X = True print("Input: ", operand_X) result = not operand_X print('Result: ', result) ...
Read MoreWhat does these operators mean (** , ^ , %, //) ?
In Python, there are various types of operators used to perform specific functions, such as (**), (^), (%), and (//). The (**) operator represents exponentiation, (^) represents bitwise XOR, (%) represents the modulus operation, and (//) represents floor division. In this article, we will understand the workings of these operators. Exponentiation Operator (**) The exponentiation operator (**) is used to raise a number to a power. This operator works the same as the Python pow() method. In exponentiation, you need two numbers: the first is the base (the number you want to raise), and the second is the ...
Read MoreWhat is the difference between = and == operators in Python?
The symbols "=" and "==" look similar but have different meanings and usability in Python. The "=" symbol is the assignment operator, and the "==" symbol represents a comparison operator. In this article, we will understand the difference between these two and how to use them. The "=" Operator The "=" operator in Python is the assignment operator. It is used to assign a value to a variable. You put the variable on the left side and the value or expression on the right side. The value on the right is stored in the variable on the left. ...
Read MoreWhat is different in OR and AND operators in Python?
The OR and AND operators are the most commonly used logical operators in Python. These operators are used to perform decision-making operations by combining multiple conditions. In this article, we will understand what OR and AND operators are in Python and how they differ, along with examples for better understanding. AND Operator in Python The logical AND operator in Python needs two operands. It returns True if both operands are true, and it returns False if either of the operands is false. This operator is mostly used in situations where you want to make sure that two conditions ...
Read MoreWhat is modulo % operator in Python?
The modulo operator is denoted by the "%" symbol in Python. It returns the remainder of the division between two numeric operands, making it useful for solving problems ranging from simple arithmetic to complex mathematical operations. Syntax The modulo operator works by returning the remainder after dividing two numbers ? result = a % b Where a and b are the operands, % represents the modulo operator, and result stores the remainder of dividing a by b. Modulo Operator with Integers Using the modulo operator with integers is the most common use ...
Read MoreWhat is tilde (~) operator in Python?
In Python, the bitwise operator ~ (pronounced as tilde) is a complement operator. It takes one bit operand and returns its complement. If the operand is 1, it returns 0, and if it is 0, it returns 1. For example, consider the 4-bit binary number (1100)2. By performing the tilde operation, each bit is flipped and results in (0011)2. Syntax result = ~operand Tilde Operation on Decimal Numbers When we perform a tilde operation on decimal numbers, the following steps are involved − Convert the decimal number ...
Read MoreWhat is operation of <> in Python?
The operator was a comparison operator in Python 2 used to check if two values are not equal. This operator has been removed in Python 3 and replaced with != for the same functionality. Syntax Python 2 (Deprecated) variable1 variable2 Python 3 (Current) variable1 != variable2 Both operators return True if the values are not equal, and False if they are equal. Python 2 Example (Historical) In Python 2, the operator worked as follows ? # Python 2 only a = 10 b = 20 ...
Read More