第三课:python基础.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* 第三课 python基础 字符串索引和分片 a=“hello,world” print(a[1])打印下标为1的字母 (结果:e) print(a[1:5])打印下标为1到5的字母,但不包含5 (结果:ello) print(a[1:])打印下标从1往后的所有字母 (结果:ello,world) print(a[:5])打印下标在5以前的所有字母,不包含5 (结果:hello) print(a[-1])打印最后一个字母 (结果:d) print(a[-5:-2])打印从右到左下标为2到5的字母 (结果:wor) 字符串操作函数 test=abcdefg print(test.capitalize())首字母大写 (结果:Abcdefg) print(test.count(a))统计a的个数 (结果:1)print(test.find(c))查找a的下标 (结果:0)print(test.isalnum()) isalnum如果是字母或数字,返回一个非零数;否则返回为0(true or false)(结果:true) print(test.isalpha()) isalpha如果是字母,返回一个非零数;否则返回为0(true or false) (结果:true) print(test.replace(a,b)) 将a替换成b (结果:bbcdefg) 字符串操作函数 test=abcdef print(test.lower())将全部字母转换为小写打印出 (结果:abcdef) print(test.upper())将全部字母转换为大写打印出 (结果:ABCDEF) print(test.split(c))从“c”处将字符串分裂 (结果:[ab, def]) print(test.strip())(结果:abcdef) print(len(test))计算字符串长度 (结果:6) test=- path=re:\book print(path) 元组 元组跟列表的区别是元组里面的数据一旦定义,不可以修改,不可以删除,不可以增加,只可以读取 test=(a,b,c) print(test[2]) 列表 test=[a,b,c‘] print(test[2]) test.append(d) print(test) test=[a,b,c,d] test.pop(3)#按下标 print(test) test=[a,b,c,d] test.remove(“d”)#按成员名称 print(test) 列表 test=[a,b,c] test.insert(1,d)#指定位置插入数据print(test) test.reverse()#颠倒顺序 test=[d,b,c] test.sort() #排序 print(test) 字典 可指定下标 test={姓名:二狗,性别:男,班级:三年级二班} test.clear() print(test) print(test.get(“性别”))#获得指定键的值 test.update({“性别”:“女”})#更新键值 print(test) test.pop(“性别”)#删除键值对 条件控制 test=3 if test2: print(test2) elif test==2: print(test=2) else: print(test2) while循环 test=3 while test==3: print(test=3) for循环 test=[a,b,c,d] for i in test: print(i) break和continue test=[a,b,c,d] for i in test: print(i) break a test=[a,b,c,d] for i in test: print(i) continue print(i) a,b,c,d range函数使用 for i in range(10): print(i) for i in range(1,10): print(i) 抛出异常 test=s try: print(int(test)) except Exception as e: print(e) *

文档评论(0)

此项为空 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档