Python Prog--phase 2 Doc 2
Python Prog--phase 2 Doc 2
LECTURE – 26
=>In This Mode of development, Python Programmer can write a single statement and immediately
Python Environment gives Result.
=>In this Mode of Development, we are unable to re-use the code in other part of the Program bcoz
Interactive Approach is unable to provide to save the code. So Interactive Approach is not
recommended to develop Real Time applications.
=>Examples
>>> a=10
>>> b=20
>>> c=a+b
>>> print(a)-----------10
>>> print(b)-----------20
>>> print(c)-----------30
=>In this mode development, Python Programmer writes batch OR group of statements, Save those
=>In Real Time applications, we use Batch Mode approach only because It allows us to save the
Batch of statements / Instructions on Some File Name and we can re-use those statements in other
part of the Project.
a=10
b=20
c=a+b
print(a)
print(b)
print(c)
=>Every Python Program must be given some File Name with an extension .py
=>Hence with Batch Mode approach, we develop Programs where as with Interactive approach we
test one instruction at a time.
=>We always develop Programs by using Batch Mode approach for Solving Real Time Problems.
=>To develop Programs in bacth Mode approach, we need to use IDEs ( Interactive Development
Environment).
2. Edit Plus
3. PyCharm
5. Anakonda Spider
6. VS Code
7. Google Clab
8. Atom
9. Sublime Text.....etc
=>From IDES (2) to (9) are not comming along python Software Installation and They must be
installed Explicitly.
Programs on Batch Mode
addopex1.py
a=10
b=20
c=a+b
print(a)
print(b)
print(c)
addopex2.py
a=10
b=20
c=a+b
print("--------------------------")
print("Val of a=",a)
print("Val of b=",b)
print("Sum=",c)
print("--------------------------")
addopex3.py
MulOpex1.py
Syntax-1 : print(Value)
(OR)
print(Value1,Value2,....Value-n)
>>> a=10
>>> print(a) 10
>>> a=12.34
>>> print(a) 12.34
>>> a=10
>>> b=2
>>> c=a+b
>>> print(a,b,c) 10 2 12
Syntax-2: print(Msg)
(OR)
print(Msg1,Msg2,...Msg-n)
(OR)
print(Msg1+Msg2+....+Msg-n)
Examples
>>> a=10
>>> print('Value of a=',a) Value of a= 10
>>> print(a," is the value a") 10 is the value a
>>> name="Rossum"
>>> print("Name of Person=",name) Name of Person= Rossum
>>> print(name," is the name of the Person") Rossum is the name of the Person
>>> a=10
>>> b=20
>>> c=a+b
>>> print(c," is the sum") 30 is the sum
>>> print("sum=",c) sum= 30
>>> print("Sum of ",a," and ",b,"=",c) Sum of 10 and 20 = 30
>>> a=10
>>> print("Value of a={}".format(a)) Value of a=10
>>> print("{} is the value of a".format(a)) 10 is the value of a
>>> a=100
>>> b=200
>>> c=a+b
>>> print("Sum of {} and {}={}".format(a,b,c)) Sum of 100 and 200=300
>>> a=10
>>> b=20
>>> c=30
>>> d=a+b+c
>>> print("sum of ",a,",",b," and ",c,"=",d) sum of 10 , 20 and 30 = 60
>>> print("Sum of {},{} and {}={}".format(a,b,c,d)) Sum of 10,20 and 30=60
=>This Syntax generates / Displays Message Cum Values by using format specifiers
=>In Python Programming, For Displaying Integer Data, we use %d format specifier
=>Note That, if any value / data does not contain format specifier then we must convert that values /
data into str type by using str()
Examples:
>>> a=10
>>> print("Value of a=%d" %a) Value of a=10
>>> print("%d is the value a" %a) 10 is the value a
>>> a=10
>>> b=20
>>> c=a+b
>>> print("Sum of %d and %d = %d" %(a,b,c)) Sum of 10 and 20 = 30
>>> a=10
>>> b=2.3
>>> c=a+b
>>> print("sum of %d and %f=%f" %(a,b,c)) sum of 10 and 2.300000=12.300000
>>> print("sum of %d and %0.2f=%0.3f" %(a,b,c)) sum of 10 and 2.30=12.300
>>> print("sum of %0.2f and %0.2f=%0.3f" %(a,b,c)) sum of 10.00 and 2.30=12.300
>>> sno=10
>>> sname="Rossum"
>>> marks=22.22
>>> print("My Number is %d and Name is %s and marks=%0.2f" %(sno,sname,marks))
My Number is 10 and Name is Rossum and marks=22.22
>>> a=12.23
>>> b=34.567
>>> print("a=%d and b=%d" %(a,b)) a=12 and b=34
>>> lst=[10,"Rossum",33.34,True,2+3j]
>>> print("Content of lst=",lst) Content of lst= [10, 'Rossum', 33.34, True, (2+3j)]
>>> print("Content of lst={}".format(lst)) Content of lst=[10, 'Rossum', 33.34, True, (2+3j)]
>>> print("Content of lst=%d" %lst) TypeError: %d format: a real number is required, not list
>>> print("Content of lst=%s" %str(lst)) Content of lst=[10, 'Rossum', 33.34, True, (2+3j)]
>>> d={10:"Apple",20:"Mango"}
=>This Syntax display the values Horizontally (Same Line) end with specified Symbols
Examples:
>>> r=range(10,21)
>>> print(r,type(r))
range(10, 21) <class 'range'>
>>> for v in r:
... print(v)
...
10
11
12
13
14
15
16
17
18
19
20
>>> for v in r:
... print(v,end="->")-----10->11->12->13->14->15->16->17->18->19->20->
>>> lst=[10,"Rossum",33.34,True,2+3j]
Special Point:
>>> s="python"
>>> s="python"
>>> lst=[10,"Rossum"]
1. input()
Syntax:- varname=input()
=>here input() is used for Reading the any type of data in the form of str from Key Board and place
that value in LHS Varname.
=>Programatically, we can convert str type data into any possible data type value by using Typcasting
Techniques.
2. input(message)
Syntax:- varname=input(Message)
=>Here Message represents any string data and It is one of the User-Prompting Message
=>here input(Message) is used for Reading the any type of data in the form of str from Key Board and
place that value in LHS Varname along with It also gives User-Prompting Message.
=>Programatically, we can convert str type data into any possible data type value by using Typcasting
Techniques.
#program for accepting Two Numerical Values from KBD and Multiply them
#MulEx1.py
a=float(s1)
b=float(s2)
print(a,type(a))
print(b,type(b))
c=a*b
print("="*50)
print("value of a={}".format(a))
print("value of b={}".format(b))
print("Mul={}".format(c))
print("="*50)
#program for accepting Two Numerical Values from KBD and Multiply them
#MulEx2.py
#program for accepting Two Numerical Values from KBD and Multiply them
#MulEx3.py
#program for accepting Two Numerical Values from KBD and Multiply them
#MulEx4.py
#program for accepting Two Numerical Values from KBD and Multiply them
#MulEx5.py
#program for accepting Two Numerical Values from KBD and Multiply them
#MulEx6.py
print("Mul={}".format(float(input("Enter First Value:"))*float(input("Enter Second Value:"))))
#Program for cal area and Perimeter of Rectangle
#RectAreaPeri.py
l=float(input("Enter Length:"))
b=float(input("Enter Breadth:"))
#cal Area of Rect
area=l*b
#cal Perimeter
peri=2*(l+b)
#display result
print("*"*40)
print("\tLength=%0.2f" %l)
print("\tBreadth=%0.2f" %b)
print("\tArea of Rectangle=%0.2f" %area)
print("\tPerimter of Rectangle=%0.2f" %peri)
print("*"*40)
rad=float(input("Enter Radius:"))
ac=3.14*rad*rad
pc=2*3.14*rad
print("*"*50)
print("\t\tRadious=%0.2f" %rad)
print("\t\tArea of Circle=%0.2f"%ac)
print("\t\tPerimeter of Circle=%0.2f" %pc)
print("*"*50)
LECTURE – 29
Operators and Expressions in Python
=>An Operator is a symbol, which is used for Performing Certain Operation on given Object Data /
Values and gives Result.
=>If two or More Objects OR Values Connected with an Operator then it is called Expression.
=>In otherwords, An Expression is a collection of Objects / Values Connected with an Operator.
=>In Python Programming, we have 7 Operators. They are
1. Arithmetic Operators
2. Assigment Operator
3. Relational Operators ( Comparision Operators)
4. Logical Operators( Comparision Operators )
5. Bitwise Operators (Most Imp)
6. Membership Operators
a) in operator
b) not in operator
7. Identity Operators
a) is operator
b) is not operator
=>The purpose of Arithmetic Operators is that "To Perform Arithmetic Operations such as
Addition,Substraction, Multiplications etc..".
=>If two or More Objects OR Values Connected with Arithmetic Operators then we call it as Arithmetic
Expression.
=>Python Programming Contains 7 Arithmetic Operators. They are given in the following Table
1. + Addition print(a+b)---->13
2. - Substraction print(a-b)----->7
3. * Multiplication print(a*b)----->30
4. / Division print(a/b)------>3.3333333333333335
(float Quotient)
7. ** Exponentiation print(a**b)------>1000
NOTE:
2. Assigment Operator
=>The purpose of assignment operator is that " To assign or transfer Right Hand Side (RHS) Value /
Expression Value to the Left Hand Side (LHS) Variable "
=>The Symbol for Assigment Operator is single equal to ( = ).
=>In Python Programming,we can use Assigment Operator in two ways.
1. Single Line Assigment
2. Multi Line Assigment
1. Single Line Assigment:
=>With Single Line Assigment at a time we can assign one RHS Value / Expression to the single
LHS Variable Name.
Examples:
>>> a=10
>>> b=20
>>> c=a+b
>>> print(a,b,c) 10 20 30
Var1,Var2.....Var-n= Expr1,Expr2...Expr-n
Examples:
>>> a,b=10,20
>>> print(a,b) 10 20
>>> c,d,e=a+b,a-b,a*b
>>> print(c,d,e) 30 -10 200
>>> sno,sname,marks=10,"Rossum",34.56
>>> print(sno,sname,marks) 10 Rossum 34.56
>>> a,b=10,20
>>> print(a,b) 10 20
#Swapvalues.py
#SquareRootEx.py
NOTE: ord() is pre-defined Function which gives UNICODE Value for any Alphabet ,Symbols,
and digits
---chr() is pre-defined Function which gives Alphabet ,Symbols, and digits for UNICODE Value.
>>> "python">"python"
False
>>> "python">"PYTHON"
True
>>> ord('A')
65
>>> ord('B')
66
>>> ord('Z')
90
>>> ord('p')+ord('y')+ord('t')+ord('h')+ord('o')+ord('n')
674
>>> ord('P')+ord('Y')+ord('T')+ord('H')+ord('O')+ord('N')
482
>>> chr(65)
'A'
>>> chr(97)
'a'
>>> "INDIA">"INDIA"
False
>>> "INDIA">"INDAI"
True
>>> "PYTHON">="PYTHON"[::-1]
True
>>> "MADAM">="MADAM"[::-1]
True
>>> ord("@")
64
>>> ord("&")
38
>>> "@#$%">"&*(#"-------------True
>>> #"1234">"4321"
>>> ord("1")
49
>>> ord("4")
52
>>> "1234">"4321"
False
>>> "1234">"4320"
False
>>> ord('0')
48
>>> chr(90)
'Z'
>>> chr(65)
'A'
>>> chr(48)
'0'
>>> chr(49)
'1'
>>> chr(50)
'2'
=>The purpose of Logical Operators is that "To compare the result of Two or More Relational
Expressions".
=>If Two or More Relational Expressions are connected with Logical Operators then It is called
Loogical Expressions.
=>The result of Loogical Expressions is either True or False.
=>The Loogical Expressions is also called Compound Condition(More than one Test Cond).
=>In Python Programming, we have 3 Logical Operators. They are given in the following Table.
Examples:
=>If Two or More Relational Expressions are connected with "and" operator and If the First relational
Expression is False then PVM Will not evalute Rest of the Relational Expressions and The result of
entire Logical Expressions is False. This Process of Evalulation is called Short Circuit Evaluation.
=>The Functionality of "or" Operators described by using the following Truth table.
Examples:
=>If Two or More Relational Expressions are connected with "or" operator and If the First relational
Expression is True then PVM Will not evalute Rest of the Relational Expressions and The result of
entire Logical Expressions is True. This Process of Evalulation is called Short Circuit Evaluation.
3. "not" Operator
True False
False True
Examples:
>>> a=True
>>> print(a)------------True
>>> print(not a)------False
>>> a=False
>>> print(a)-----------False
>>> print(not a)-------True
>>> print(10>20)--------False
>>> print(not 10>20)----True
>>> print(not 10!=20)----False
>>> print(not 10==20)----True
#RelationalOperatorsEx.py
LECTURE – 31
Bitwise Operators (Most Imp)
=>The Bitwise Operators are applicable on Integer data but not on Floating Point Values bcoz floating
point values does not contain Certainity.
=>Bitwise Operators are used for Performing Operations on Integer data in the form of Bit by Bit.
=>In Otherwords, Bitwise operators First Converts Integer data into Binary Format and Performs
operations on Binary Data in the form of Bit by Bit. Since these Operators are performing Bit by Bit
on Integer Binary data and hence They named as Bitwise Operators.
=>In Python Programming, we have 6 Bitwise Operators. They are given in the following Table.
Concept: The Bitwise Left Shift Operator ( << ) shifts No. of Bits Towards Left Side By adding No. of
Zero at Right Side (depends on No. of Bits). So thatr esult value will displayed in the form of decial
number system.
Examples:
>>> a=10
>>> b=3
>>> c=a<<b
>>> print(c)-----------80
>>> print(10<<3)--------80
>>> print(3<<2)---------12
>>> print(100<<2)-----400
>>> print(12<<4)-------192
Concept: The Bitwise Right Shift Operator ( >> ) shifts No. of Bits Towards Right Side By Adding
No. of Zero at Left Side (depends on No. of Bits). So that result value will displayed in the form of
decial number system .
Examples:
>>> a=10
>>> b=3
>>> c=a>>b
>>> print(c)----------------1
>>> print(10>>2)----------2
>>> print(25>>4)----------1
>>> print(24>>3)---------3
>>> print(50>>4)--------3
>>> print(45>>2)--------11
0 0 0
1 0 1
0 1 1
1 1 1
Examples
>>> 0 | 0----------------0
>>> 1 | 0----------------1
>>> 0 | 1----------------1
>>> 1 | 1----------------1
>>> a=10
>>> b=12
>>> c=a|b
>>> print(c)----------14
>>> print(10|15)-----15
>>> print(3|4)--------7
>>> s1={10,20,30}
>>> s2={15,20,35}
>>> s3=s1.union(s2)
>>> print(s3,type(s3))---------{35, 20, 10, 30, 15} <class 'set'>
>>> s4=s1|s2 # Bitwise OR Operator
>>> print(s4,type(s4))---------{35, 20, 10, 30, 15} <class 'set'>
>>> s2={"Sberry","Apple","Guava"}
>>> s3=s1.union(s2)
>>> print(s3,type(s3))--------{'Mango', 'Guava', 'Sberry', 'Kiwi', 'Apple'} <class 'set'>
>>> s4=s1|s2 # Bitwise OR Operator
>>> print(s4,type(s4))--------{'Mango', 'Guava', 'Sberry', 'Kiwi', 'Apple'} <class 'set'>
Special Ponits
LECTURE – 32
=>The Functionality of Bitwise AND Operator is expressed by using the following Truth Table
>>> 0 & 1
0
>>> 0 & 0
0
>>> 1 & 0
0
>>> 1 & 1
1
>>> a=10
>>> b=15
>>> c=a&b
>>> print(c) 10
>>> 10 and 15 15
>>> print(3&4) 0
>>> "Keshav" and "Regular" and "Forgot" 'Forgot'
=>Syntax:- varname=~value
=>The Functionality of Bitwise Complement Operator ( ~ ) is that "It Inverts the bits".
=>Inverting the Bits are nothing but 0 becomes 1 and 1 becomes 0.
=>The Formula for Bitwise Complement Operator ( ~ ) is that " ~Value= - (Value+1)
Examples:
>>> a=4
>>> b=~a ~(0100)
-(0100+1)
-(0101)---->Whose result is -5
>>> print(b) 5
>>> print(a) 4
Bitwise XOR Operator ( ^ )
=>The Functionality of BitwiseXOR Operator is expressed by using the following Truth Table
Examples
>>> 1^0
1
>>> 1^1
0
>>> 0^1
1
>>> 0^0
0
>>>a=10
>>>b=15
>>>c=a^b 1010
1111
--------------
0101-----Result--5
>>>print(c)---5
>>> print(4^5) 1
>>> print(10^5) 15
>>> s1={10,20,30}
>>> s2={15,20,25}
>>> print(s1,type(s1)) {10, 20, 30} <class 'set'>
>>> print(s2,type(s2)) {25, 20, 15} <class 'set'>
>>> s3=s1.symmetric_difference(s2)
>>> print(s3,type(s3)) {10, 15, 25, 30} <class 'set'>
>>> s4=s1^s2 # Bitwise XOR
>>> print(s4,type(s4)) {10, 15, 25, 30} <class 'set'>
Membership Operators
=>The purpose of Membership Operators is that "To Check the Existence of Specified value in an
Iterable Object".
=>An Iterable Object is one, which contains Two or More Number of Values.
=>Note that Fundamental and NoneType Data Types are not belongs to Iterable Object.
=>In Python Programming, we have 2 Types of Membership Operators. They are
1. in
2. not in
1. in
=>If the "Value" Present in IterableObject then "in" operator Returns True
=>If the "Value" not Present in IterableObject then "in" operator Returns False
2. not in
=>If the "Value" not Present in IterableObject then "not in" operator Returns True
=>If the "Value" Present in IterableObject then "not in" operator Returns False
Examples:
>>> s="PYTHON"
>>> print(s,type(s))
PYTHON <class 'str'>
>>> "P" in s
True
>>> "p" in s
False
>>> "O" in s
True
>>> "N" not in s
False
>>> "y" not in s
True
>>> "k" not in s
True
>>> s="PYTHON"
>>> print(s,type(s))
PYTHON <class 'str'>
>>> "PYTH" in s
True
>>> "PYTH" not in s
False
>>> "THON" not in s
False
>>> "PTO" in s
False
>>> "PTO" not in s
True
>>> "HON" not in s
False
>>> "PON" not in s
True
>>> "NOH" in s
False
>>> "NOH" not in s[::-1]
False
>>> "PON" in s[::2]
False
>>> "PTO" not in s[::2]
False
>>> "PTO" not in s[::2][::-1]
True
>>> lst=[10,"Rossum",23.45,True,2+3j]
>>> print(lst,type(lst))
[10, 'Rossum', 23.45, True, (2+3j)] <class 'list'>
>>> "Rossum" in lst
True
>>> False not in lst
True
>>> True not in lst
False
>>>
>>> print(lst,type(lst))
[10, 'Rossum', 23.45, True, (2+3j)] <class 'list'>
>>> 'Ross' in lst
False
>>> 'Ross' not in lst[1]
False
>>> 'Ross' in lst[1]
True
>>> 'Ross' not in lst[1][::-1]
True
>>> 'Ross'[::-1] not in lst[1][::]
True
>>> lst=[10,"Rossum",23.45,True,2+3j]
>>> lst=[10,"Rossum",23.45,True,"2+3j"]
>>> s="PYTHON"
>>> s in s True
>>> d1={10:"Apple",20:"Mango",30:"Kiwi"}
>>> print(d1,type(d1)) {10: 'Apple', 20: 'Mango', 30: 'Kiwi'} <class 'dict'>
>>> d1 in d1 TypeError: unhashable type: 'dict'
>>> 10 in d1
True
>>> "Apple" in d1
False
>>> (30,"Kiwi") in d1
False
>>> (30,"Kiwi") in d1.items()
True
>>> for x in d1:
... print(x)
...
10
20
30
>>> "Apple" in d1.values()
True
>>> "Apple"[::-1] not in d1.values()[::-1] TypeError: 'dict_values' object is not subscriptable
LECTURE – 33
=>The purpose of Identity Operators is that "To Check the memory address of Objects".
=>In Python Programming , We have Two Types of Identity Operators. They are
1. is
2. is not
1. is
=>Here 'is' operator returns True provided Obj1 and Obj2 Memory Addresses are Same
=>Here 'is' operator returns False provided Obj1 and Obj2 Memory Addresses are Different
2. is not
=>Here 'is not' operator returns True provided Obj1 and Obj2 Memory Addresses are Different
=>Here 'is not ' operator returns False provided Obj1 and Obj2 Memory Addresses are Same
Examples
>>> a=None
>>> b=None
>>> d1={10:"Apple",20:"Mango",30:"Kiwi"}
>>> d2={10:"Apple",20:"Mango",30:"Kiwi"}
>>> print(d1,id(d1))
{10: 'Apple', 20: 'Mango', 30: 'Kiwi'} 2681935187584
>>> print(d2,id(d2))
{10: 'Apple', 20: 'Mango', 30: 'Kiwi'} 2681935187712
>>> d1 is d2
False
>>> d1 is not d2
True
>>> s1={10,20,30,40}
>>> s2={10,20,30,40}
>>> print(s1,id(s1))
{40, 10, 20, 30} 2681935942080
>>> print(s2,id(s2))
{40, 10, 20, 30} 2681935941632
>>> s1 is s2
False
>>> s1 is not s2
True
>>> fs1=frozenset({10,20,30,40})
>>> fs2=frozenset({10,20,30,40})
>>> print(fs1,id(fs1))
frozenset({40, 10, 20, 30}) 2681935943200
>>> print(fs2,id(fs2))
frozenset({40, 10, 20, 30}) 2681935942976
>>> fs1 is fs2
False
>>> fs1 is not fs2
True
>>> l1=[10,20,30,40]
>>> l2=[10,20,30,40]
>>> print(l1,id(l1))
[10, 20, 30, 40] 2681935234176
>>> print(l2,id(l2))
[10, 20, 30, 40] 2681935235008
>>> l1 is l2
False
>>> l1 is not l2
True
>>> t1=(10,20,30,40)
>>> t2=(10,20,30,40)
>>> print(t1,id(t1))
(10, 20, 30, 40) 2681935633584
>>> print(t2,id(t2))
(10, 20, 30, 40) 2681935637584
>>> t1 is t2
False
>>> t1 is not t2
True
>>> s1="PYTHON"
>>> s2="PYTHON"
>>> print(s1,id(s1))
PYTHON 2681939497776
>>> print(s2,id(s2))
PYTHON 2681939497776
>>> s1 is s2
True
>>> s1 is not s2
False
>>>
>>> s1="PYTHON"
>>> s2="PYTHOn"
>>> s1 is not s2
True
>>> s1 is s2
False
>>> b1=bytes([10,20,30,40])
>>> b2=bytes([10,20,30,40])
>>> print(b1,id(b1))
b'\n\x14\x1e(' 2681935345920
>>> print(b2,id(b2))
b'\n\x14\x1e(' 2681935343760
>>> b1 is b2
False
>>> b1 is not b2
True
>>> b1=bytearray([10,20,30,40])
>>> b2=bytearray([10,20,30,40])
>>> print(b1,id(b1))
bytearray(b'\n\x14\x1e(') 2681939498032
>>> print(b2,id(b2))
bytearray(b'\n\x14\x1e(') 2681939497648
>>> b1 is b2
False
>>> b1 is not b2
True
>>> r1=range(10,20)
>>> r2=range(10,20)
>>> print(r1,id(r1))
range(10, 20) 2681935341408
>>> print(r2,id(r2))
range(10, 20) 2681935346016
>>> r1 is r2
False
>>> r1 is not r2
True
>>> c1=2+3j
>>> c2=2+3j
>>> print(c1,id(c1))
(2+3j) 2681934897040
>>> print(c2,id(c2))
(2+3j) 2681934900656
>>> c1 is c2
False
>>> c1 is not c2
True
>>> a=True
>>> b=True
>>> print(a,id(a))
True 140732600896360
>>> print(b,id(b))
True 140732600896360
>>> a is b
True
>>> a is not b
False
>>> a=1.2
>>> b=1.2
>>> print(a,id(a))
1.2 2681934897424
>>> print(b,id(b))
1.2 2681934897456
>>> a is b
False
>>> a is not b
True
Here 0---256 values contains Same Address when we store same value in Different Objects
Other than those Values They Contins Different Address
>>> a=300
>>> b=300
>>> print(a,id(a))
300 2681934896976
>>> print(b,id(b))
300 2681934900624
>>> a is b
False
>>> a is not b
True
>>>
>>>
>>> a=10
>>> b=10
>>> print(a,id(a))
10 2681933857296
>>> print(b,id(b))
10 2681933857296
>>> a is b
True
>>> a is not b
False
>>> a=0
>>> b=0
>>> print(a,id(a))
0 2681933856976
>>> print(b,id(b))
0 2681933856976
>>> a is b
True
>>> a is not b
False
>>> a=256
>>> b=256
>>> print(a,id(a))
256 2681933865168
>>> print(b,id(b))
256 2681933865168
>>> a is b
True
>>> a is not b
False
>>> a=257
>>> b=257
>>> print(a,id(a))
257 2681934900752
>>> print(b,id(b))
257 2681934900720
>>> a is b
False
>>> a is not b
True
Here -1 to -5 values contains Same Address when we store same value in Different Objects
Other than those Values They Contins Different Address
>>> a=-1
>>> b=-1
>>> print(a,id(a))
-1 2681933856944
>>> print(b,id(b))
-1 2681933856944
>>> a is b
True
>>> a is not b
False
>>> a=-5
>>> b=-5
>>> print(a,id(a))
-5 2681933856816
>>> print(b,id(b))
-5 2681933856816
>>> a is b
True
>>> a is not b
False
>>> a=-10
>>> b=-10
>>> print(a,id(a))
-10 2681934900720
>>> print(b,id(b))
-10 2681934900752
>>> a is b
False
>>> a is not b
True
>>> print(a,id(a))
300 2681934900560
>>> print(b,id(b))
300 2681934900560
>>> a is b
True
>>> a is not b
False
>>> print(a,id(a))
-10 2681934900688
>>> print(b,id(b))
-10 2681934900688
>>> a is b
True
>>> a is not b
False
>>> a,b=1.2,1.2
>>> print(a,id(a))
1.2 2681934897424
>>> print(b,id(b))
1.2 2681934897424
>>> a is b
True
>>> a is not b
False
>>> l1,l2=[10,"RS",23.45],[10,"RS",23.45]
>>> print(l1,id(l1))
[10, 'RS', 23.45] 2681939493376
>>> print(l2,id(l2))
[10, 'RS', 23.45] 2681939493312
>>> l1 is l2
False
>>> l1 is not l2
True
>>> a=1000
>>> b=a # Deep Copy
>>> print(a,id(a))
1000 2681934900592
>>> print(b,id(b))
1000 2681934900592
>>> a is b
True
>>> a is not b
False
>>> a=1.2
>>> b=a # Deep Copy
>>> print(a,id(a))
1.2 2681934897552
>>> print(b,id(b))
1.2 2681934897552
>>> a is b
True
>>> l1=[10,"RS",23.45]
>>> l2=l1 # Deep Copy
>>> print(l1,id(l1))
[10, 'RS', 23.45] 2681935235008
>>> print(l2,id(l2))
[10, 'RS', 23.45] 2681935235008
>>> l1 is l2
True
>>> l1 is not l2
False
>>> l1=[10,"RS",23.45]
>>> l2=l1.copy() # Shallow Copy
>>> print(l1,id(l1))
[10, 'RS', 23.45] 2681939493312
>>> print(l2,id(l2))
[10, 'RS', 23.45] 2681939493376
>>> l1 is l2
False
>>> l1 is not l2
True
=>The Ternary Operator in Python Programming Language is " if .. else Operator ".
=>Syntax:
varname = Expr1 if Test Cond else Expr2
Explanation:
=>Here "if" and "else" are the keywords
=>Here Test Cond is to be evaluated either to be True or False
=>If the Test Condition is True then PVM Executes Expr1 and whose Result assigned to Varname
=>If the Test Condition is False then PVM Executes Expr2 and whose Result assigned to Varname
=>Hence varname contains result of either Expr1 or Expr2
#program for biggest of two numbers
#BiTwoEqual.py
#PalindromeEx1.py
#VowelWord.py