当前位置:   article > 正文

python 初始化 元组_在Python中重新初始化元组

python中如何初始化一个三元组

python 初始化 元组

Python | 重新初始化元组 (Python | Reinitializing tuple)

In this tutorial, we will learn how can we reinitialize a tuple with a new set of elements/objects?

在本教程中,我们将学习如何使用一组新的元素/对象重新初始化元组?

To reinitialize a tuple, we can use tuple() or a pair of round brackets (), the steps are,

重新初始化元组 ,我们可以使用tuple()或一对圆括号() ,步骤是,

  1. Reinitialize the tuple using () or tuple()

    使用()或tuple()重新初始化元组

  2. Reassign the new set of objects/elements

    重新分配新的对象/元素集

Consider the below program,

考虑下面的程序,

  1. # Reinitializing a tuple in Python
  2. # tuple creation
  3. x = ("Shivang", 21, "Indore", 9999867123)
  4. # printing original tuple
  5. print("x: ", x)
  6. print("len(x): ", len(x))
  7. print("type(x): ", type(x))
  8. print()
  9. # Reinitializing tuple using tuple()
  10. x = tuple()
  11. # assigning new objects
  12. x = (10, 20, 30, 40, 50)
  13. print("x: ", x)
  14. print("len(x): ", len(x))
  15. print("type(x): ", type(x))
  16. print()
  17. # Reinitializing tuple using ()
  18. x = ()
  19. # assigning new objects
  20. x = ("Amit", 18, "Jaipur", 98.24, 8888888888)
  21. print("x: ", x)
  22. print("len(x): ", len(x))
  23. print("type(x): ", type(x))
  24. print()

Output

输出量

  1. x: ('Shivang', 21, 'Indore', 9999867123)
  2. len(x): 4
  3. type(x): <class 'tuple'>
  4. x: (10, 20, 30, 40, 50)
  5. len(x): 5
  6. type(x): <class 'tuple'>
  7. x: ('Amit', 18, 'Jaipur', 98.24, 8888888888)
  8. len(x): 5
  9. type(x): <class 'tuple'>

翻译自: https://www.includehelp.com/python/reinitializing-a-tuple.aspx

python 初始化 元组

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/305784
推荐阅读
相关标签
  

闽ICP备14008679号