Found 34484 Articles for Programming

What is the difference between the != and <> operators in Python?

Malhar Lathkar
Updated on 30-Jul-2019 22:30:21

189 Views

In Python 2.x, both != and operators are available to check if two operands are not equal. Both return true if operands are not equal and false if they are equal.In Python 3.x, operator has been deprecated.

What is the difference between = and == operators in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:43:01

1K+ Views

In Python = symbol is defined as assignment operator. It requires one variable on its left and an expression on its right. Value of the expression on right is assigned to variable on left. Expression and name of variable are not interchangeable.>>> a=10 >>> b=20 >>> c=a+b >>> a,b,c (10, 20, 30) >>> a+b=c SyntaxError: can't assign to operatorThe == symbol is a comparison operator and called equal to operator. It returns true if operands on either side are equal, otherwise it returns false>>> 10+2 == 10 False >>> (10+2) == 12 True >>> 'computer' == 'Computer' False >>> 'computer' == "computer" True

What is different in OR and AND operators in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:21:41

5K+ Views

In Python, and and or (along with not) are defined as logical operators. Both require two operands which may evaluate to true or false.The and operator returns True only if both operands are True.>>> a=50 >>> b=25 >>> a>40 and b>40 False >>> a>100 and b>> a==0 and b==0 False >>> a>0 and b>0 TrueThe or operator returns True if either operand is true.>>> a=50 >>> b=25 >>> a>40 or b>40 True >>> a>100 or b>> a==0 or b==0 False >>> a>0 or b>0 True

What is different in | and OR operators in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:22:24

1K+ Views

In Python or is a logical operator and | is a bitwise operator. The or operator requires two opeans of any type and may be true or false. It returns true if any one operand evaluates to true.>>> a=50 >>> b=25 >>> a>40 or b>40 True >>> a>100 or b>> a==0 or b==0 False >>> a>0 or b>0 TrueThe | operator takes bits as operands and returns 1 if any one operand is 1>>> a=10   #0000 1010 >>> bin(a) '0b1010' >>> b=20   #0001 0100 >>> bin(b) '0b10100' >>> c=a|b >>> c 30         #0001 1110 >>> bin(c) '0b11110'

What is different in & and AND operators in Python?

babita aryaa
Updated on 30-Jul-2019 22:30:21

364 Views

Yes, they both are different as AND is a logical operator which is used two compare between two values whereas  & is used as a bitwise operator.

What are boolean operators in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:23:13

7K+ Views

The logical operators and, or and not are also referred to as boolean operators. While and as well as or operator needs two operands, which may evaluate to true or false, not operator needs one operand evaluating to true or false.Boolean and operator returns true if both operands return true.>>> a=50 >>> b=25 >>> a>40 and b>40 False >>> a>100 and b>> a==0 and b==0 False >>> a>0 and b>0 TrueBoolean or operator returns true if any one operand is true>>> a=50 >>> b=25 >>> a>40 or b>40 True >>> a>100 or b>> a==0 or b==0 False >>> a>0 or ... Read More

What is modulo % operator in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:23:56

365 Views

The % symbol is defined in Python as modulo operator. It can also be called remainder operator. It returns remainder of division of two numeric operands (except complex numbers).>>> a=10 >>> b=3 >>> a%b 1 >>> a=12.25 >>> b=4 >>> a%b 0.25 >>> a=-10 >>> b=6 >>> a%b 2 >>> a=1.55 >>> b=0.05 >>> a%b 0.04999999999999996

What is tilde (~) operator in Python?

Malhar Lathkar
Updated on 18-Jun-2020 08:35:21

5K+ Views

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 1For example if a=60 (0011 1100 in binary) its complement is -61 (-0011 1101) stored in 2's complement>>> a=60 >>> bin(a) '0b111100' >>> b=~a >>> a 60 >>> >>> b -61 >>> bin(b) '-0b111101

How to subtract days from a date in JavaScript?

Abhishek
Updated on 04-Oct-2023 12:55:19

29K+ Views

In this tutorial, we will learn how to subtract days from a date in JavaScript. To subtract days from a JavaScript Date object, use the setDate() method. Under that, get the current days and subtract days. JavaScript date setDate() method sets the day of the month for a specified date according to local time. Following are the methods we can use to subtract days from a date in JavaScript − Using the setTime() and getTime() methods Using the setDate() and getDate() methods ... Read More

What is behavior of ++ and -- operators in Python?

Pythonista
Updated on 26-Feb-2020 07:36:49

159 Views

In C/C++ and Java etc, ++ and -- operators are defined as increment and decrement operators. In Python they are not defined as operators.In Python objects are stored in memory. Variables are just the labels. Numeric objects are immutable. Hence they can't be incremented or decremented.However, prefix ++ or -- doesn't give error but doesn't perform either.>>> a=5 >>> b=6 >>> ++a 5 >>> --b 6Postfix ++ or -- produce errors>>> a=5 >>> b=6 >>> a++ SyntaxError: invalid syntax >>> b-- SyntaxError: invalid syntax

Advertisements