Python自学:第四章 遍历切片】的更多相关文章

# -*- coding: GBK -*- players = ['charles', 'martina', 'michael', 'florence', 'eli'] print("Here are the first three players on my team:") for player in players[:3]: print (player.title()) 输出为: Here are the first three players on my team: Charle…
# -*- coding: GBK -*- players = ['charles', 'martina', 'michael', 'florence', 'eli'] print(players[0:3]) 输出为: ['charles', 'martina', 'michael'] 2.中间提取 # -*- coding: GBK -*- players = ['charles', 'martina', 'michael', 'florence', 'eli'] print(players[…
# -*- coding: GBK -*- my_foods = ['pizza', 'falafel', 'carrot cake'] friend_foods = my_foods[:] print("My favorite foods are:") print(my_foods) print("\nMy friend's favorite foods are:") print(friend_foods) 输出为: My favorite foods are:…
# -*- coding: GBK -*- magicians = ['alice', 'david', 'carolina'] for magician in magicians: print(magician.title() + ", that was a great trick!") print("I can't wait to seee your next trick," + magician.title() + ".\n") print…
# -*- coding: GBK -*- magicians = ['alice', 'david', 'carolina'] for magician in magicians: print(magician.title() + ", that was a great trick!") print("I can't wait to seee your next trick," + magician.title() + ".\n") 输出为:…
# -*- coding: GBK -*- magicians = ['alice', 'david', 'carolina'] for magician in magicians: print(magician.title() + ", that was a great trick!") 输出为: Alice, that was a great trick! David, that was a great trick! Carolina, that was a great trick…
2016/1/28学习内容 第四章 Python字符串与正则表达式之正则表达式 正则表达式是字符串处理的有力工具和技术,正则表达式使用预定义的特定模式去匹配一类具有共同特征的字符串,主要用于字符串处理,可以快速,准确地完成复杂的查找,替换等处理要求. Python中,re模块提供了正则表达式操作所需要的基本功能 正则表达式元字符 元字符: . 匹配除换行符意外的任意单个字符 元字符: * 匹配位于*之前的0个或多个字符 元字符: + 匹配位于+之前的1个或多个字符 元字符: | 匹配位于|之前或…
第四章. 控制流 控制语句后面要加冒号: 1)    if语句 if guess == number: print 'Congratulations, you guessed it.' # New block starts here elif guess < number: print 'No, it is a little higher than that' # Another block else: print 'No, it is a little lower than that' if…
Python的高级应用(一) 本章内容: 内置函数 生成器 迭代器 装饰器 JSON和PICKLE的简单用法 软件目录结构规范 一.内置函数 1.数学运算类 abs(x) 求绝对值1.参数可以是整型,也可以是复数2.若参数是复数,则返回复数的模 complex([real[, imag]]) 创建一个复数 divmod(a, b) 分别取商和余数注意:整型.浮点型都可以 float([x]) 将一个字符串或数转换为浮点数.如果无参数将返回0.0 int([x[, base]])  将一个字符转换…
在python中,所有集合都可以迭代,在python语言内部,迭代器用于支持 for循环 构建和扩展集合类型 逐行遍历文本文件 列表推导,字典推导和集合推导 元组拆包 调用函数时,使用*拆包实参 本章涵盖的话题 语言内部使用 iter(...) 内置函数处理可迭代对象的方式如何使用 Python 实现经典的迭代器模式详细说明生成器函数的工作原理如何使用生成器函数或生成器表达式代替经典的迭代器如何使用标准库中通用的生成器函数如何使用 yield from 语句合并生成器案例分析:在一个数据库转换工…