43
-Tuple assignment solves this problem neatly:
-One way to think of tuple assignment is astuple packing/unpacking.
In tuple packing, the values on the left are ‘packed’ together in a tuple:
-In tuple unpacking,the values in a tuple on the right are ‘unpacked ‘intothe variables/names on the
right:
-The right side can be any kind of sequence (string,list,tuple)
Example:
-To split an email address in to user name and a domain
>>>mailid='
[email protected]'
>>>name,domain=mailid.split('@')
>>>print name god
>>> print (domain) abc.org
4.OPERATORS:
Operators are the constructs which can manipulate the value ofoperands.
Consider theexpression4 + 5 = 9.Here,4 and 5 are called operandsand+ is called operator
Types ofOperators:
-Python language supportsthe following types of operators
·Arithmetic Operators
·Comparison (Relational)Operators
·Assignment Operators
·Logical Operators
·BitwiseOperators
·MembershipOperators
·IdentityOperators
(a, b) = (b, a)
>>>b =("George",25,"20000")#tuplepacking
>>>(name, age, salary)=b#tupleunpacking
>>>name
'George'
>>>age
25
>>>salary
'20000'
# tuplepacking>>>b = ("George", 25, "20000")