0% found this document useful (0 votes)
2 views2 pages

Bitwise AND Operator

The document explains the Bitwise AND operator (&) with its syntax and functionality illustrated through a truth table. It provides examples of its usage with integers and sets, highlighting the results of various operations. Additionally, it notes the TypeErrors that occur when attempting to use the operator with incompatible data types like strings and floats.

Uploaded by

shah2013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Bitwise AND Operator

The document explains the Bitwise AND operator (&) with its syntax and functionality illustrated through a truth table. It provides examples of its usage with integers and sets, highlighting the results of various operations. Additionally, it notes the TypeErrors that occur when attempting to use the operator with incompatible data types like strings and floats.

Uploaded by

shah2013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

============================================================

4. Bitwise AND Operator ( & )


============================================================
=>Syntax: varname = Value1 & Value2
=>The Functionality of Bitwise AND Operator ( & ) is expressed with the following
Truth Table.
-----------------------------------------------------------------
----------------------
Value1 Value2 Value1& Value2
-----------------------------------------------------------------
----------------------
0 0 0
1 1 1
1 0 0
0 1 0
-----------------------------------------------------------------
----------------------
-------------------------------
Examples
-------------------------------
>>> 0&0----------------0
>>> 1&1---------------1
>>> 1&0---------------0
>>> 0&1---------------0
--------------------------------
Examples
--------------------------------
>>> a=10--------------------- 1010
>>> b=5---------------------- 0101
--------------------
>>> c=a&b 0000
--------------------
>>> print(c)------0
>>> 10 and 5-------5
>>> 5 and 10--------10
>>> print(7&3)-------3
------------------------------------------------------------------
Special Points--Most Imp
------------------------------------------------------------------
>>> s1={10,20,30}
>>> s2={40,20,50}
>>> s3=s1.intersection(s2)
>>> print(s3,type(s3))-------------{20} <class 'set'>
-------------------
>>> s1={10,20,30}
>>> s2={40,20,50}
>>> s3=s1&s2 # Bitwise AND Operator (& )
>>> print(s3,type(s3))---------{20} <class 'set'>
------------
>>> s1={10,20,30}
>>> s2={40,60,50}
>>> s3=s1&s2
>>> print(s3,type(s3))----set() <class 'set'>
>>> "Apple" & "Mango"-------TypeError: unsupported operand type(s) for &: 'str' and
'str'
>>> "Apple" and "Mango"------'Mango'
-------------------------------------------------------
>>> s1={1.2,2.3,4.5}
>>> s2={7.2,2.3,8.5}
>>> s3=s1&s2
>>> print(s3,type(s3))------{2.3} <class 'set'>
>>> 1.2 & 2.3--------------TypeError: unsupported operand type(s) for &: 'float'
and 'float'
>>> "$" and "#"-----------'#'
>>> "$"&"#" ----------------TypeError: unsupported operand type(s) for &: 'str' and
'str'
=========================================x=========================================
============

You might also like