首页 > 编程语言 > 详细

python_列表/元组/元组列表以及如何使用

时间:2017-11-16 16:58:22      阅读:237      评论:0      收藏:0      [点我收藏+]
1、list是处理一组有序项目的数据结构
1 #定义一个列表
2 list=[1,2,3]
3 print type(list)
4 print list[0]
输出:

  <type ‘list‘>

  1

 

2、元组与列表类似,支持异构,任意嵌套

1 #定义一个元组
2 tuple1 = (4,5,6)
3 print type(tuple1)
4 print tuple1[1]

输出:

  <type ‘tuple‘>
  5

1 #定义一个元组列表
2 tuple2 = [(1,2,3),(4,5,6)]
3 print type(tuple2)
4 print tuple2[0]
5 print tuple2[0][1]

输出:

  <type ‘list‘>
  (1, 2, 3)
  2

python_列表/元组/元组列表以及如何使用

原文:http://www.cnblogs.com/sxming/p/7722080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!