博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
016序列
阅读量:4561 次
发布时间:2019-06-08

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

序列:包括列表、元祖和字符串等,共同特点如下:

1)都可以通过索引得到每一个元素

2)默认索引值总是从0开始(Python还支持负数索引)

3)可以通过分片的方法得到一个范围内的元素的集合

4)有很多共同的操作符(重复操作符*、拼接操作符+、成员关系操作符in)

>>> a='I love FishC.com'>>> list(a)['I', ' ', 'l', 'o', 'v', 'e', ' ', 'F', 'i', 's', 'h', 'C', '.', 'c', 'o', 'm']>>> max(1,3.14,556,-5)556>>> min(1,3.14,556,-5)-5>>> tuple1=[1,2,3,4,5,6]>>> max(tuple1)6>>> sum(tuple1)21>>> sum(tuple1,100)121>>> sorted(tuple1)[1, 2, 3, 4, 5, 6]>>> reversed(tuple1)
>>> list(reversed(tuple1))[6, 5, 4, 3, 2, 1]>>> enumerate(tuple1)
>>> list(enumerate(tuple1))[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]

list:len/sum/max/min/sorted/renversed/enumerate/zip

max=tuple1[0]for each in tuple1:    if each>max:        max=eachreturn max
def min(x):    least = x[0]    for each in x:        if each < least:            least = each    return leastprint(min('123456789'))
def sum(x):    result = 0        for each in x:        if (type(each) == int) or (type(each) == float):            result += each        else:            continue    return resultprint(sum([1, 2.1, 2.3, 'a', '1', True]))

 

 

def sum(x):

    result = 0

   

    for each in x:

        if (type(each) == int) or (type(each) == float):

            result += each

        else:

            continue

 

    return result

 

print(sum([1, 2.1, 2.3, 'a', '1', True]))

转载于:https://www.cnblogs.com/samyll/p/8178044.html

你可能感兴趣的文章
Binary XML file : Error inflating class com.esri.android.map.MapView
查看>>
grep,awk和sed
查看>>
.NET Core WebAPI IIS 部署问题
查看>>
SystemTap 静态探针安装包
查看>>
redis五种数据类型的使用
查看>>
浏览器全屏之requestFullScreen全屏与F11全屏
查看>>
软件包管理:rpm命令管理-安装升级与卸载
查看>>
旋转图像
查看>>
字符串中的数字(字符串、循环)
查看>>
15.select into
查看>>
运行web项目端口占用问题
查看>>
Java Spring-IOC和DI
查看>>
【NOIP1999】【Luogu1015】回文数(高精度,模拟)
查看>>
Linux上安装Python3.5
查看>>
crt安装
查看>>
git切换分支报错:error: pathspec 'origin/XXX' did not match any file(s) known to git
查看>>
c++中static的用法详解
查看>>
转 我修改的注册表,但是程序运行起来,还是记着以前的
查看>>
图片轮播功能
查看>>
第六周小组作业:软件测试和评估
查看>>