May 2017
Intermediate to advanced
280 pages
6h 2m
English
In this section, you will see addition and multiplication.
By using the + operator, two tuples can be added as shown:
>>> avenger1 = ("Iron-man", "captain", "Thor")>>> avenger2 = ("Vision", "Sam")>>> avenger1 + avenger2('Iron-man', 'captain', 'Thor', 'Vision', 'Sam')>>>
By using the * operator, you can perform multiplication:
>>> language = ("Python","html")>>> language*2('Python', 'html', 'Python', 'html')>>>
Let's check the memory address of the tuple after multiplication:
>>> a = language*2>>> a('Python', 'html', 'Python', 'html')>>> id(a[0])45826944>>>>>> id(a[2])45826944>>>>>> id(a[1])45828896>>> id(a[3])45828896>>>
Now, you can see that the first and third strings both possess the same memory location.
Read now
Unlock full access