美文网首页
Python Day13 元组

Python Day13 元组

作者: 读书的番茄 | 来源:发表于2017-04-27 10:20 被阅读0次

1、元组与列表的区别

1.1.tuple与list类似,简单说tuple不可以修改, 而list可以修改
1.2.list创建时,用“[ ]”。tuple创建时大部分是用“()”和“,”
>>> list1 = [1]
>>> tuple1 = (1, )
>>> tuple1
(1,)
>>> list1
[1]

2、相同方式

2.1.访问tuple
>>> tuple2= (1, 2, 3, 4, 5)
>>> tuple1[2]
3

>>> 2 * tuple1
(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
2.2.更新tuple
>>> tuple3
('键盘', '鼠标', '显示器', '主机')
>>> tuple3 = tuple3[:2] + ('电源',) + tuple3[2:]
>>> tuple3
('键盘', '鼠标', '电源', '显示器', '主机')
2.3.删除tuple
>>> del tuple2
>>> tuple2
Traceback (most recent call last):
  File "", line 1, in
    tuple2
NameError: name 'tuple2' is not defined
2.4.其他,‘<’'>','or','in'等

相关文章

  • Python Day13 元组

    1、元组与列表的区别 1.1.tuple与list类似,简单说tuple不可以修改, 而list可以修改 1.2....

  • Python基础之元组、字典,集合详解

    之前总结了Python列表,这篇总结Python的元组,字典和集合。 一 元组 tuple Python 的元组与...

  • Python 元组

    Python 元组 Python的元组与列表类似,不同之处在于元组的元素不能修改。 1.1 定义元组使用小括号,列...

  • Lesson 016 —— python 元组

    Lesson 016 —— python 元组 Python 的元组与列表类似,不同之处在于元组的元素不能修改。 ...

  • python小课堂08 - 基本数据类型元组篇

    python小课堂08 - 基本数据类型元组篇 python中的元组 python中的元组,也是作为基础数据类型之...

  • python 基础 - 元组

    Python 元组 Python 的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列表使用方括号...

  • 元祖

    Python 元组 Python的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列表使用方括号。...

  • Python元组常用方法

    一、前言? ✔本文是Python元组常用方法总结Python的元组与列表类似,不同之处在于元组的元素不能修改,元组...

  • 学习python第六天总结

    一python的基本类型 元组 python 的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列...

  • Python中的tuple元组

    Python中的tuple元组 一、访问元组 Python中的元组和列表类似,不同之处在于元组中的元素不能够被修改...

网友评论

      本文标题:Python Day13 元组

      本文链接:https://www.haomeiwen.com/subject/wnsgzttx.html