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) -->['!', ' ...
随机推荐
- PC110305/UVA10188
根据我的规律,每天solved3题就感觉不行了~但是今天好像做水题做上瘾了,不过PC的题目尽管水,水得还是可以让人有进步. 这题OJ自动测评真心坑,题目看起来十分简单,测评返回三种可能: Accept ...
- (转)JSP中四种传递参数的方法:
1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf="index.jsp"?a= ...
- 结合使用 Oracle Database 11g 和 Python
结合使用 Oracle Database 11g 和 Python 本教程介绍如何结合使用 Python 和 Oracle Database 11g. 所需时间 大约 1 个小时 概述 Python ...
- File System Shell
Overview appendToFile cat chgrp chmod chown copyFromLocal copyToLocal count cp du dus expunge get ge ...
- android 代码混淆及问题大集锦
最近在需要对所开发的项目进行了代码混淆,在android studio中开启代码混淆其实还是挺方便的,不过因为代码混淆产生的问题非常多,特别是对于一些涉及到反射的第三方库经常因为名称的变化导致无法使用 ...
- 【微机】验证负数以补码存储程序 C语言
微机中验证负数以补码存储程序 一.相关基础知识 负数的补码等于它的反码加1,即在其反码的最低位加1就为该数的补码,且在计算机中负数以补码形式进行存储. .int型占4字节(32位二进制)char型占1 ...
- (转载)KL距离,Kullback-Leibler Divergence
转自:KL距离,Kullback-Leibler Divergence KL距离,是Kullback-Leibler差异(Kullback-Leibler Divergence)的简称,也叫做相对 ...
- Loading CSS without blocking render
The principles behind these techniques aren't new. Filament group, for example, have published great ...
- 【HTTP】Speed and Mobility: An Approach for HTTP 2.0 to Make Mobile Apps and the Web Faster
This week begins face to face meetings at the IETF on how to approach HTTP 2.0 and improve the Inter ...
- 基于springMVC+springSecurity3.x+Mybaits3.x的权限系统,,开放源码,支持开源
原文地址:http://blog.csdn.net/mmm333zzz/article/details/16863543/