If a is (1, 2, 3)(a) what is the difference (if any) between a * 3 and (a, a, a)?

Опубликовано: 24 Октябрь 2024
на канале: Portal Express
158
4

Q. If a is (1, 2, 3)
(a) what is the difference (if any) between a * 3 and (a, a, a)?
(b) is a * 3 equivalent to a + a + a ?
(c) what is the meaning of a[1:1] ?

(d) what is the difference between a[1:2] and a[1:1] ?

Website Link :-
https://www.pathwalla.com/2020/03/if-...

Answer =

A = a*3 will print three times of tuple in a single tuple
(1,2,3,1,2,3,1,2,3)
(a,a,a) will print nested tuple.
((1,2,3),(1,2,3),(1,2,3))

B = yes

C = it mean that it will not give any e value because it is start from index number 1 but stop at index number 1 but as we know that in slicing it is start from 1 and stop up at 1 so it will print empty tuple.

D = a[1:2] will print value at index number 1 while,
a[1:1] will print empty tuple.