W3Schools được tối ưu hóa cho việc học và đào tạo. Ví dụ có thể được đơn giản hóa để cải thiện việc đọc và học tập. Hướng dẫn, tài liệu tham khảo và ví dụ được xem xét liên tục để tránh lỗi, nhưng chúng tôi không thể đảm bảo tính chính xác đầy đủ của tất cả các nội dung. Trong khi sử dụng W3Schools, bạn đồng ý đã đọc và chấp nhận các điều khoản sử dụng, cookie và chính sách bảo mật của chúng tôi.
Bản quyền 1999-2022 bởi dữ liệu refsnes. Đã đăng ký Bản quyền. W3Schools được cung cấp bởi W3.CSS.
W3Schools is Powered by W3.CSS.
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luận Combination of above functionalities can solve the problem for us. In this, we compute the summation using lambda functions and extend the logic to keys using map[].
Python3
test_tup1
=
[
10
,
4
__7
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]0____11
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]2
=
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
,
____1010________The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]9
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]22____23
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]4
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]2
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]3
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]25
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]7
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]8
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
=
8The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]3
[
0The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]7
[
3
Đầu ra: & nbsp;
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]
Phương pháp số 3: Sử dụng phương thức Tuple [] và cho vòng lặpMethod #2 : Using map[] + zip[] + sum[] The combination of above functions can also be used to achieve this particular task. In this, we add inbuilt sum[] to perform summation and zip the like indices using zip[] and extend logic to both tuples using map[].
Python3
test_tup1
=
[
10
,
4
__7
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]0____11
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]2
=
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
,
____1010________The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]9
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]22____23
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]4
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]2
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]3
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
test_tup1
7=
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]3
[
=
1[
=
____________,
6,
7The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
=
8The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]3
[
0The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]7
[
3Đầu ra: & nbsp;
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]
Phương pháp số 3: Sử dụng phương thức Tuple [] và cho vòng lặp
Python3
test_tup1
=
[
10
,
4
__7
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]0____11
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]2
=
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]5
,
____1010________The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]9
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]25
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]7
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]8
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]31
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]7
test_tup1
6The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]35
=
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]37
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]38
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]39
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]40
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]41
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]43__
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]47
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]48
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]50
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]35
=
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]3
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]54
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]1
[
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]57
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]6
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]7
[
3Đầu ra
The original tuple 1 : [10, 4, 5] The original tuple 2 : [2, 5, 18] Resultant tuple after addition : [12, 9, 23]