博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python的数据结构 -- 序列
阅读量:6890 次
发布时间:2019-06-27

本文共 866 字,大约阅读时间需要 2 分钟。

shoppingList = ['apple','banana','cat','dog','duck']#Indexing and 'subscription operation'print('The first item is',shoppingList[0])print('The second item is',shoppingList[1])print('the third item is',shoppingList[2])print('item -1 is',shoppingList[-1])print('item -2 is',shoppingList[-2])#Slicing on a listprint('Form the 1 to 3 is',shoppingList[1:3])print('From the 2 to 4 is',shoppingList[2:4])print('Form the 1 to -1 is',shoppingList[2:-3])print('From the start to end is',shoppingList[:])#Slicing on a Stringname='keritafranklin'print('From the 1 to 3 is',name[1:3])print('From the 2 to 4 is',name[2:4])print('From the 1 to -1 is',name[1:-1])print('From the start to end is',name[:])#序列的特性:#1、索引操作符#2、切片操作符#  -1指的是最后一个、-2指的是倒数第二个。以此类推#  如果在某个区间没有元素,则返回[]#  如果用这样引用[:],则表示输出所有元素#  切片时从第一个序列开始,到第二个序列前截止

2015/4/21

转载于:https://www.cnblogs.com/kerita/p/4447924.html

你可能感兴趣的文章
Access text files using SQL statements by DB Query Analyzer
查看>>
微信公众号开发将war包导入新浪sae出现错误
查看>>
01-Jvm 内存区域复习笔记
查看>>
9.7 迭代
查看>>
纪念中国反毒之父—王江民
查看>>
C#(数据结构):1.顺序表结构(2)
查看>>
C语言 文件操作| 文件打开
查看>>
通过XMLHttpRequest和jQuery实现ajax的几种方式
查看>>
JS_小教程
查看>>
Could not load file or assembly 'Microsoft.AnalysisServices.SharePoint.Integration'
查看>>
Delphi中Chrome Chromium、Cef3学习笔记(六)
查看>>
oracle 11g RAC 安装前准备脚本
查看>>
【翻译】Sencha Touch 2入门:创建一个实用的天气应用程序之一
查看>>
redux-form(V7.4.2)笔记(三之补充)使用Flow初步
查看>>
组策略部署软件----将部署的软件分类
查看>>
无对象控制
查看>>
运维人员究竟如何提升价值,持续获得高薪?
查看>>
win7 下设置挂载Linux服务器nfs共享的数据
查看>>
演示:标准ACL的配置、及使用技巧、和相关局限
查看>>
动态可配置表单的设计构思
查看>>