Python - 元组(tuple) 详解 及 代码
元组(tuple) 详解 及 代码
本文地址: http://blog.csdn.net/caroline_wendy/article/details/17290967
元组是存放任意元素集合,不能修改其内容;
len()是求元组的长度, 可以使用下标标示符("[]")去访问元组的数据;
元组内还可以包含元组, 可以通过新建一个元组, 扩充已有的元素;
代码如下:
# -*- coding: utf-8 -*- #====================
#File: abop.py
#Author: Wendy
#Date: 2013-12-03
#==================== #eclipse pydev, python3.3 #元组, 表示不能修改的一组的值 zoo = ('python', 'elephant', 'penguin')
print('Number of animals in the zoo is', len(zoo)) new_zoo = ('monkey', 'camel', zoo) #新建元组, 不是修改
print('Number of cages in the new zoo are', len(new_zoo))
print('All animals in new zoo are', new_zoo)
print('Animals brought from old zoo are', new_zoo[2]) #把zoo放入new_zoo的第2个位置(从0开始)
print('Last animal brought from old zoo is', new_zoo[2][2]) #元组包含元组
print('Number of animals in the new zoo is', len(new_zoo)-1+len(new_zoo[2])) #减去当前元素[2]和[2]的长度(3-1+3)
输出:
Number of animals in the zoo is 3
Number of cages in the new zoo are 3
All animals in new zoo are ('monkey', 'camel', ('python', 'elephant', 'penguin'))
Animals brought from old zoo are ('python', 'elephant', 'penguin')
Last animal brought from old zoo is penguin
Number of animals in the new zoo is 5
Python - 元组(tuple) 详解 及 代码的更多相关文章
- Python - 字典(dict) 详解 及 代码
字典(dict) 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/17291329 字典(dict)是表示映射的数据 ...
- Python推导式详解,带你写出比较精简酷炫的代码
Python推导式详解,带你写出比较精简酷炫的代码 前言 1.推导式分类与用法 1.1 列表推导 1.2 集合推导 1.3 字典推导 1.4 元组推导?不存在的 2.推导式的性能 2.1 列表推导式与 ...
- (转)python collections模块详解
python collections模块详解 原文:http://www.cnblogs.com/dahu-daqing/p/7040490.html 1.模块简介 collections包含了一些特 ...
- python之struct详解
python之struct详解 2018-05-23 18:20:29 醉小义 阅读数 20115更多 分类专栏: python 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议 ...
- Python 字符串方法详解
Python 字符串方法详解 本文最初发表于赖勇浩(恋花蝶)的博客(http://blog.csdn.net/lanphaday),如蒙转载,敬请保留全文完整,切勿去除本声明和作者信息. ...
- Python中dict详解
from:http://www.cnblogs.com/yangyongzhi/archive/2012/09/17/2688326.html Python中dict详解 python3.0以上,pr ...
- python/ORM操作详解
一.python/ORM操作详解 ===================增==================== models.UserInfo.objects.create(title='alex ...
- 深度学习之卷积神经网络(CNN)详解与代码实现(一)
卷积神经网络(CNN)详解与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10430073.html 目 ...
- python之数据类型详解
python之数据类型详解 二.列表list (可以存储多个值)(列表内数字不需要加引号) sort s1=[','!'] # s1.sort() # print(s1) -->['!', ' ...
随机推荐
- 在调用Qt库来实现功能过程中的一些总结
1.对于QTabWidget中tab名字的变化.当其中只有一个&时,Qt Assistant中给出的解释是:If the tab's label contains an ampersand, ...
- Java之字符串学习
java中String的使用十分频繁,是我们要学习的重点,在说String之前,我们要知道堆跟栈的区别. java中的数据类型分原生数据类型(primitived types)有八种(byte,cha ...
- MVVM模式应用 之的RelayCommand的使用
实现MVVM模式Command是立下了汗马功劳.当然ICommand要引用using System.Windows.Input命名空间. 比如: (1)我们在xaml页面有一个Button按钮,我们需 ...
- Setup VSFTPD Server with Virtual Users On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3
We have already shown you How to Setup VSFTPD Server on CentOS 6.5/6.4 in our previous article. In t ...
- javascript动态添加效果
<script type="text/javascript"> window.onload=function(){ $("#ch").click(f ...
- 不错的轮播插件flexslider
http://flexslider.woothemes.com/ $('.flexslider').flexslider({ animation:'slide', //滑动效果:翻页效果,默认为fad ...
- Activity启动过程简要介绍
无论是通过点击应用程序图标来启动Activity,还是通过Activity内部调用startActivity接口来启动新的Activity,都要借助于应用程序框架层的ActivityManagerSe ...
- ligerUI路径问题
ligerUI放mv的Content目录下,路径为固定的并且必须引进一下文件 <link href="~/Content/Ligerui/Source/lib/ligerUI/skin ...
- Quartz1.8.5例子(九)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- 利用jquery操作Radio方法小结
用Radio来实现用户的选择效果,在项目中积累了一些利用JQUERY来操作Radio的方法,这里与大家分享下 在开发中经常会用到Radio来实现用户的选择效果,我在项目中积累了一些利用JQUERY来操 ...