In [1]:

```
#Program to demonstrate the use of Comma operator
#Result
print "Addition = ",2+3," \nSubtraction = ",5-4
```

In [1]:

```
#Program to demonstrate the use of Conditional operator with two values
#Result
#in python if..else statement can be written similar to conditional operator
#prints Result = 4 if 2 == 3, otherwise Result = 5
print "Result = ",4 if 2==3 else 5
```

In [2]:

```
#Program to use Conditional operator with two statements
#Result
#in python if..else statement can be written similar to conditional operator
#prints True if 3>2, otherwise prints False
print "True" if 3>2 else "False"
```

In [3]:

```
#Program to use increment operator as prefix
#Variable declaration
x = 10
y = 20
#Calculation
#there is no ++/-- operator in python
z = x * y
y += 1
a = x * y
#Result
print z," ",a
```

In [4]:

```
#Program to use increment operator as prefix
#Variable declaration
x = 10
y = 20
#Calculation
#there is no ++/-- operator in python
y += 1
z = x * y
a = x * y
#Result
print z," ",a
```

In [5]:

```
#Program to find the size and address of integer and float variables
#import python module
#sys python module is required for getsizeof() function.
import sys
#Variable declaration
#No specific float type variable declaration is available in python. If we
#assign a floating point value to a variable,
#it will be treated as floating point variable
x = 2
y = 2.0
#Result
#In python, integer variable uses 12 bytes and float variable uses 16 bytes of
#memory to store the variables
#sys.getsizeof() function returns the size of variable in bytes which is similar
#to sizeof() operator
#id() function returns the address of variables which is similar to '&' operator
print "Size (x) = ",sys.getsizeof(x)
print "Size (y) = ",sys.getsizeof(y)
print "Address of x = ",id(x),"and y = ",id(y)
```

In [6]:

```
#Program to use various relational operators and display their return values
#Result
#int() function is used to convert the boolean return value of the relational
#expression to integer/binary
print "Condition : Return Values"
print "10 != 10 : ",int(10 != 10)
print "10 == 10 : ",int(10 == 10)
print "10 >= 10 : ",int(10 >= 10)
print "10 <= 100 : ",int(10 <= 100)
print "10 != 9 : ",int(10 != 9)
```

In [1]:

```
#Program uses conditional operator to determine the value of 'b'depending the inputted value of 'a'
#Reads Input value for a
a = raw_input("Enter Any Integer either above 5 or below 5 :-")
a = int(a)
#In python, raw_input() is used to read values
#Calculation
#Assigns b = 3 if a > 5, otherwise b = 4
b = 3 if a > 5 else 4
#Result
print "Calculated Value of b is :- ",b
```

In [2]:

```
#Program to determine the value of 'b' using conditional operator
#Input
a = raw_input("Enter Any Integer either above 5 or below 5 :-")
a = int(a)
#In python, raw_input() is used to read values
#Calculation
#Assigns b = 3 if a == 5, otherwise b = 4
b = 3 if a == 5 else 4
#Result
print "Calculated Value of b is :- ",b
```

In [3]:

```
#Read three variables x, y and z and Using conditional statements, evaluate
#values of variables a, b and c.
#Perform the sum with two sets of variables. Check whether the sums are equal or not
#and print appropriate messages.
#Reads three Input values for x,y and z
x = raw_input("Enter Value of x ")
x = int(x)
y = raw_input("Enter Value of y ")
y = int(y)
z = raw_input("Enter Value of z ")
z = int(z)
#In python, raw_input() is used to read values
#Calculation
#Assigns a = 3 if x >= 5, otherwise a = 4
a = 3 if x >= 5 else 4
#Result
print "Calculated Value of a is :- ",a
#Calculation
#Assigns b = 10 if y <= 8, otherwise b = 9
b = 10 if y <= 8 else 9
#Result
print "Calculated Value of b is :- ",b
#Calculation
#Assigns c = 20 if z == 10, otherwise c = 30
c = 20 if z == 10 else 30
#Result
print "Calculated Value of c is :- ",c
#Calculation
m = x + y + z
n = a + b + c
#Result
print "Addition of x,y,z is ",m,"(m)"
print "Addition of a,b,c is ",n,"(n)"
print "m & n NOT EQUAL" if m != n else "m & n ARE EQUAL"
```

In [4]:

```
#Use of logical operators
#Result
#In python, not equal to can be represented using both != and <>.
print "Condition : Return Values"
print "5 > 3 && 5 < 10 : ",int(5 > 3 & 5 < 10)
print "8 > 5 || 8 < 2 : ",int(8 > 5 | 8 < 2)
print "!(8 == 8) : ",int(8 != 8)
```

In [4]:

```
#Print logic 1 if input character is capital otherwise 0
#Import
import sys
#Variable initialization
#raw_input() function is used to read a character from the keyboard in Python 2.7
#ord() function converts the character into its corresponding ASCII integer
#Reads Input value for x
x = raw_input("Enter a Character : ")
x = ord(x)
#In python, raw_input() is used to read values
#Condition
y = 1 if (x >= 65) and (x <= 90) else 0
#Result
print "Y : ",y
```

In [5]:

```
#Display logic 0 if one reads a character through keyboard otherwise logic 1.
#ASCII values for 0 to 9 are 48 to 57 respectively
#Variable initialization
#raw_input() function is used to read a character from the keyboard in Python 2.7
#ord() function converts the character into its corresponding ASCII integer
#Reads Input value for x
x = raw_input("Enter The Character or Integer : ")
x = ord(x)
#In python, raw_input() is used to read values
#Condition
y = 1 if (x >= 48) and (x <= 57) else 0
#Result
print "Value of Y = ",y
```

In [6]:

```
#Display 1 if inputted number is between 1-100 otherwise 0.
#Use the logical AND operator
#Variable initialization
#Reads Input value for x
x = raw_input("Enter numbers : ")
x = int(x)
#In python, raw_input() is used to read values
#Condition
z = 1 if (x >= 1) and (x <= 100) else 0
#Result
print "Z = ",z
```

In [8]:

```
#Display 1 if inputted number is either 1 or 100 otherwise 0.
#Use the logical OR operator
#Variable initialization
#Reads Input value for x
x = raw_input("Enter numbers : ")
x = int(x)
#In python, raw_input() is used to read values
#Condition
z = 1 if (x == 1) or (x == 100) else 0
#Result
print "Z = ",z
```

In [9]:

```
#Display 1 if inputted number is except 100 otherwise 0.
#Use the logical NOT operator
#Variable initialization
#Reads Input value for x
x = raw_input("Enter number : ")
x = int(x)
#In python, raw_input() is used to read values
#Condition
z = 1 if (x != 100) else 0
#Result
print "Z : ",z
```

In [10]:

```
#Shift inputted data by two bits right
#Variable initialization
#Reads Input value for x
x = raw_input("Read The Integer from keyboard (x) :- ")
x = int(x)
#In python, raw_input() is used to read values
#bitwise shifting
x >>= 2
y = x
#Result
print "The Right shifted data is = ",y
```

In [11]:

```
#Shift inputted data by two bits to the left
#Variable initialization
#Reads Input value for x
x = raw_input("Read The Integer from keyboard (x) :- ")
x = int(x)
#In python, raw_input() is used to read values
#bitwise shifting
x <<= 3
y = x
#Result
print "The Left shifted data is = ",y
```

In [12]:

```
#Use bitwise AND operator between the two integers and display the results
#Variable initialization
#Reads Input value for x
a = raw_input("Read The Integers from keyboard (a & b) :- ")
a = int(a)
b = raw_input("Read The Integers from keyboard (a & b) :- ")
b = int(b)
#In python, raw_input() is used to read values
#bitwise operation
c = a & b
#Result
print "The Answer after ANDing is (C) = ",c
```

In [13]:

```
#operate OR operation on two integers and display the result
#Variable initialization
#Reads Input value for x
a = raw_input("Read The Integers from keyboard (a & b) :- ")
a = int(a)
b = raw_input("Read The Integers from keyboard (a & b) :- ")
b = int(b)
#In python, raw_input() is used to read values
#bitwise operation
c = a | b
#Result
print "The Oring operation betwen a & b in c = ",c
```

In [14]:

```
#Exclusive OR operation between the two integers and display the result
#Variable initialization
#Reads Input value for x
a = raw_input("Read The Integers from keyboard (a & b) :- ")
a = int(a)
b = raw_input("Read The Integers from keyboard (a & b) :- ")
b = int(b)
#In python, raw_input() is used to read values
#bitwise operation
c = a ^ b
#Result
print "The data after Exclusive OR operation is in c = ",c
```

In [ ]:

```
```