简体   繁体   English

我怎样才能制作元组的元组?

[英]How can I make tuple of tuples?

I'm trying to make tuple of tuples!我正在尝试制作元组元组!

a = ('Oct 27, 2021', 'Oct 24, 2021', 'Oct 20, 2021', 'Oct 20, 2021')
b = ('1',)

>>> h=tuple([a+b])
(('Oct 27, 2021', 'Oct 24, 2021', 'Oct 20, 2021', 'Oct 20, 2021', '1'),)

What I want is this我想要的是这个

(('Oct 27, 2021', 'Oct 24, 2021', 'Oct 20, 2021', 'Oct 20, 2021'), ('1'))

I've tried to use the zip but didn't work!我试过使用 zip 但没有用! in my opinion it should be easy, but I can't find the answer.在我看来这应该很容易,但我找不到答案。 Could I get some help on this?我能得到一些帮助吗?

Tuples are unchangedable (see: https://www.w3schools.com/python/python_tuples.asp ).元组是不可更改的(请参阅: https : //www.w3schools.com/python/python_tuples.asp )。 It means you cannot append, merge or extend them.这意味着您不能追加、合并或扩展它们。

The only way to get what you want is to directly write them as:获得所需内容的唯一方法是直接将它们写为:

(b, t)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM