I want the following results from python tuple addition
Question:
python code
test_1 = ("a", "b", "c", "d", "e", "f", "g")
test_2 = (("A", "B"), ("C", "D", "E"))
test_3 = test_1 + test_2
print(test_3)
I would like to obtain the following results
(('a', 'b', 'c', 'd', 'e', 'f', 'g'), ('A', 'B'), ('C', 'D', 'E'))
However the results are as follows.
How should I write this?
('a', 'b', 'c', 'd', 'e', 'f', 'g', ('A', 'B'), ('C', 'D', 'E'))
Answers:
Use a ,
because when you are adding it takes the second tuple and puts it into the first. But, when you use ,
its test t_3
to test_1
and test_2
. The *
shows that it is an arg.
test_1 = ("a", "b", "c", "d", "e", "f", "g")
test_2 = ("A", "B"), ("C", "D", "E")
t_3 = (test_1, *test_2)
print(t_3)
python code
test_1 = ("a", "b", "c", "d", "e", "f", "g")
test_2 = (("A", "B"), ("C", "D", "E"))
test_3 = test_1 + test_2
print(test_3)
I would like to obtain the following results
(('a', 'b', 'c', 'd', 'e', 'f', 'g'), ('A', 'B'), ('C', 'D', 'E'))
However the results are as follows.
How should I write this?
('a', 'b', 'c', 'd', 'e', 'f', 'g', ('A', 'B'), ('C', 'D', 'E'))
Use a ,
because when you are adding it takes the second tuple and puts it into the first. But, when you use ,
its test t_3
to test_1
and test_2
. The *
shows that it is an arg.
test_1 = ("a", "b", "c", "d", "e", "f", "g")
test_2 = ("A", "B"), ("C", "D", "E")
t_3 = (test_1, *test_2)
print(t_3)