Python中的N个元素增量元组
当需要创建“ N”个元素增量元组时,可以使用生成器表达式和“ tuple”方法。
以下是相同的演示-
示例
N = 3输出结果print("The value of 'N' has been initialized")
print("The number of times it has to be repeated is : ")
print(N)
my_result = tuple((elem, ) * N for elem in range(1, 6))
print("The tuple sequence is : ")
print(my_result)
The value of 'N' has been initializedThe number of times it has to be repeated is :
3
The tuple sequence is :
((1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5))
解释
“ N”的值已初始化,并显示在控制台上。
将具有特定元素的元组(在给定范围内乘以“ N”倍)分配给变量。
生成此序列,并在控制台上将其显示为输出。
以上是 Python中的N个元素增量元组 的全部内容, 来源链接: utcz.com/z/333637.html