Assignment operator and Logical operator in Python

 


Assignment operator and Logical operator in Python

Assignment Operators

Assignment operators are used to assign values to variables. Assignment operators are:

Considering a=4 & b=2 & c=6

Operator

Name

Description

Example

Same As

Explain

=

Assign

Assigns values from right to left

a = 5

a = 5

c=a+b assigns value of a+b int c

+=

Add & Assign

It adds the right operand to left operand and assigns the value to left operand

c += a

c = c + a

c+=a is equal to c=c+a

-=

Subtract & Assign

It subtracts the right operand from left operand and assign the value to left operand

c -= 3

c = c - a

c-=a is equal to c=c-a

*=

Multiply & Assign

It multiplies the right operand with left operand and assigns the value to left operand

c *= 3

c = c * a

a*=a is equal to c=c*a

/=

Divide & Assign

It divides left operand with the right operand and assign the value to left operand

c /= a

c = c / a

c/=a is equal to c=c/a

%=

Modulus & Assign

It divides left operand with the right operand  and assign the remainder value to left operand

c %= a

c = c % a

c%=a is equal to c=c%a

//=

Floor & Assign

 

x //= 3

x = x // 3

 

**=

Exponent & Assign

 

x **= 3

x = x ** 3

 

&=

 

 

x &= 3

x = x & 3

 

|=

 

 

x |= 3

x = x | 3

 

^=

 

 

x ^= 3

x = x ^ 3

 

>>=

 

 

x >>= 3

x = x >> 3

 

<<=

 

 

x <<= 3

x = x << 3

 

Logical Operators

Logical operators are used to combine conditional statements:

Considering x=10 & y=20

Operator

Description

Example

Result

and 

Returns True if both statements are true

x >5 and  y < 25

True

or

Returns True if one of the statements is true

x > 5 or y < 4

True

not

Reverse the result, returns False if the result is true

not(x > 5 and y < 20)

False


<<Previous                                                  Next>>


कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

MS Excel to WhatsApp Bulk Message in single Click

Excel to WhatsApp Bulk Message VBA Code File Download VBA Note Pad File - Click here Download Excel Practice File - Click here Copy Code her...

Blogger द्वारा संचालित.