栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

PYTHON从编程到实践

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PYTHON从编程到实践

2变量和简单数据类型 2.2变量
  •  变量名只能包含字母、数字和下划线。
  • 变量名不能包含空格,但可使用下划线来分隔其中的单词。
  • 不要将Python关键字和函数名用作变量名
  • 变量名应既简短又具有描述性
  • 慎用小写字母l和大写字母O,因为它们可能被人错看成数字1和0。
2.3字符串
  • 单引号单个,双引号可迭代
  • 第一个大写—print(name.title())
  • 大写----print(name.upper())
  • 小写写—print(name.lower())
  • 合并(拼接)字符串—full_name = first_name + " " + last_name
  • 使用制表符或换行符来添加空白 – print(“Languages:ntPythonntCntJavascript”)
  • 删除空白—favorite_language.rstrip()
2.4数字
  • 可对整数执行加(+)减(-)乘(*)除(/)运算。

  • 使用两个乘号表示乘方运算–3 ** 2

  • 小数点的数字都称为浮点数

  • 使用函数 str()避免类型错误 :
    将数值23转换为字符串:

    age = 23 message = "Happy " + str(age) + "rd Birthday!" 
    
    print(message) 
    
  • 整数除法的结果只包含整数部分,小数部 分被删除。确保至少有一个操作数为浮点数,这样结果也将为 浮点数:

  • 不要企图编写完美无缺的代码;先编写行之有效的代码,再决定是对其做进一步改进,还是转而去编 写新代码。

  • Python之禅:在 Python终端会话中执行命令 import this,并粗略地浏览一下 其他的指导原则。

3列表
  • 用方括号([])来表示列表,并用逗号来分隔其中的元素

  • 索引从 0而不是 1开始 ,索引指定为-1返 回最后一个列表元素

  • 修改列表元素

     motorcycles = ['honda', 'yamaha', 'suzuki'] 
     print(motorcycles) 
    
     motorcycles[0] = 'ducati' print(motorcycles) 
    
  • 添加元素

    • 在列表末尾添加元素 —motorcycles.append(‘ducati’)
    • 在列表中插入元素 — motorcycles.insert(0, ‘ducati’) ,其中0是索引位置
    • 从列表中删除元素
      • 使用del语句删除元素 ,不保留元素— del motorcycles[0]

      • 使用方法pop()删除元素
        方法pop()可删除列表末尾的元素,并让你能够接着使用它

        motorcycles = ['honda', 'yamaha', 'suzuki']
        print(motorcycles) 
        popped_motorcycle = motorcycles.pop()  
        print(motorcycles) 
        print(popped_motorcycle)
        
      • 弹出列表中任何位置处的元素
        每当你使用pop()时,被弹出的元素就不再在列表中了。 如果你不确定该使用del语句还是pop()方法,下面是一个简单的判断标准:如果你要从列表 中删除一个元素,且不再以任何方式使用它,就使用del语句;如果你要在删除元素后还能继续 使用它,就使用方法pop()。

      • 根据值删除元素

        • 不知列表中删除值所处的位置。只知道要删除的元素的值,可使 用方法remove
        • 使用remove()从列表中删除元素时,也可接着使用它的值
        • 方法remove()只删除第一个指定的值。如果要删除的值可能在列表中出现多次,就需要 使用循环来判断是否删除了所有这样的值
        motorcycles = ['honda', 'yamaha', 'suzuki', 'ducati']
        print(motorcycles) 
        too_expensive = 'ducati'  
        motorcycles.remove(too_expensive) 
        print(motorcycles)  
        print("nA " + 
        too_expensive.title() +
        " is too expensive for me.")
        
        
3.3 组织列表
  • 使用方法 sort()对列表进行永久性排序
    • cars.sort()
    • cars.sort(reverse=True)
  • 使用函数 sorted()对列表进行临时排序
    • 不影响它们在列表中的原始排列顺
    • print(sorted(cars))
  • 倒着打印列表
    • cars.reverse() print(cars)
    • 方法reverse()永久性地修改列表元素的排列顺序,但可随时恢复到原来的排列顺序,为此 只需对列表再次调用reverse()即可
  • 确定列表的长度—len()
4.操作列表 4.1遍历整个列表
  • for magician in magicians:
  • 编写for循环时,对于用于存储列表中每个值的临时变量,可指定任何名称。然而, 选择描述单个列表元素的有意义的名称大有帮助
  • 忘记缩进会有歧义
4.3创建数值列表
  • 函数range()让Python从指定的第一个值开始数,并在到达指定的第二个值后停止

  • 要创建数字列表,可使用函数list()将range()的结果直接转换为列表

  • 列表与循环语句

    squares = [] for value in range(1,11):     
    squares.append(value**2) 
    与下同
    squares = [value**2 for value in range(1,11)] 
    
4.4使用列表的一部分
  • 切片---- print(players[0:3])
    最后三名队员,可使用切片players[-3:
  • 遍历切片 ---- for player in players[:3]:
  • 复制列表 — friend_foods = my_foods[:]
  •        my_foods.append('cannoli')      friend_foods.append('ice cream')   返回的列表不一样
    
  •       #这行不通  friend_foods = my_foods ,返回的列表一样
    
4.5元组
  • 有时候你需要创建一系列不可修改的元素, 元组可以满足这种需求。Python将不能修改的值称为不可变的,而不可变的列表被称为元组
  • 于试图修改元组的 操作是被禁止
  • 先定元组dimensions:dimensions = (200, 50)
  • 遍历元组中的所有值 ----
  • 修改元组变量 ,虽然不能修改元组的元素,但可以给存储元组的变量赋值
  • 混合使用了制表符和空格,可将文件中所有的制表符转换为空格,大多数编辑器都提供了这样的功能。
  • 建议每行不超过80字符
  • 有5行创建列表的代码, 还有3行处理该列表的代码,那么用一个空行将这两部分隔开是合适的。
5.if语句 5.1示例
cars = ['audi', 'bmw', 'subaru', 'toyota'] 
for car in cars:      
    if car == 'bmw':          
        print(car.upper())     
    else:         
        print(car.title()) 

结果:

Audi 
BMW 
Subaru 
Toyota 
5.2条件测试
  • 每条if语句的核心都是一个值为True或False的表达式,这种表达式被称为条件测试
  • 检查是否相等---- car == ‘bmw’
  • 两个大小写不同的值会被视为不相等,将变量的值转换为小写,再进行比较— car.lower() == ‘audi’
  • 检查是否不相等 — !=
    • 大多数条件表达式都检查两个值是否相等,但有时候检查两个值是否不等的效率 更高
  • 比较数字
  • 检查多个条件
      1. 使用and检查多个条件
      • 为改善可读性,可将每个测试都分别放在一对括号内----(age_0 >= 21) and (age_1 >= 21)
      1. 使用or检查多个条件
  • 检查特定值是否包含在列表中,可使用关键字in— ‘mushrooms’ in requested_toppings
  • 检查特定值是否不包含在列表中,可使用关键字not in
  • 布尔表达式
5.3if 语句
  • 示例
    if conditional_test :
        do something 

记得缩进

  • if-else 语句,总是会执行 两个操作中的一个
age = 17  
if age >= 18:
    print("You are old enough to vote!")
    print("Have you registered to vote yet?")  
else:     
    print("Sorry, you are too young to vote.")     
    print("Please register to vote as soon as you turn 18!") 
  • if-elif-else 结构 ,经常需要检查超过两个的情形
age = 12 
if age < 4:     
    print("Your admission cost is $0.")  
elif age < 18:     
    print("Your admission cost is $5.")  
else:     
    print("Your admission cost is $10.") 

根据缩进判断动作属于该条件或整体的

  • 使用多个 elif 代码块
age = 12 
 
if age < 4:     
    price = 0
elif age < 18:     
    price = 5 
elif age < 65:     
    price = 10  
else:     
    price = 5 
print("Your admission cost is $" + str(price) + ".") 
  • 省略else 代码块,
    • Python并不要求if-elif结构后面必须有else代码块,
    • 全部使用elif每个代码块都仅在通过了相应的测试时才会执行
    • else是一条包罗万象的语句,只要不满足任何if或elif中的条件测试,其中的代码就会执行, 这可能会引入无效甚至恶意的数
  • 测试多个条件 :
    if-elif-else结构功能强大,但仅适合用于只有一个条件满足的情况:遇到通过了的测试后, Python就跳过余下的测试
  • IF EISE只能执行一个条件,满足便停止,可搭配for改善该缺点
requested_toppings = ['mushrooms', 'green peppers', 'extra cheese'] 
 
for requested_topping in requested_toppings:
    if requested_topping == 'green peppers':                   
    print("Sorry, we are out of green peppers right      
    now.")      
    else: 
        print("Adding " + requested_topping + ".") 
 
print("nFinished making your pizza!") 
  • 确定列表不是空的
requested_toppings = [] 
 
if requested_toppings:    
    for requested_topping in requested_toppings:             
    print("Adding " + requested_topping + ".")     
    print("nFinished making your pizza!")
else:
    print("Are you sure you want a plain pizza?")
5.5设置if 语句的格式 6字典 6.1示例
  • alien_0 = {‘color’: ‘green’, ‘points’: 5}
6.2使用字典
  • 字典是一系列键—值对。每个键都与一个值相关联,可使用键来访问与之 相关联的值。与键相关联的值可以是数字、字符串、列表乃至字典
  • 要获取与键相关联的值,可依次指定字典名和放在方括号内的键—print(alien_0[‘color’])
  • 添加键—值对 —alien_0[‘x_position’] = 0
  • 编写能自动生成大量键—值对的代码时,通常都需要先 定义一个空字典
  • 修改字典中的值 — alien_0[‘color’] = ‘yellow’
  • 删除键—值对 ,可使用del语句将相应的键—值对彻底删除。使用del语句时, 必须指定字典名和要删除的键—del alien_0[‘points’]
  • 由类似对象组成的字典
favorite_languages = {
    'jen': 'python',     
    'sarah': 'c',     
    'edward': 'ruby',     
    'phil': 'python', 
    } 

确定需要使用多行来定义字典时,在输入左花括号后按回车 键,再在下一行缩进四个空格,指定第一个键—值对,并在它后面加上一个逗号
将较长的print语句分成多行:

print("Sarah's favorite language is " +                     
    favorite_languages['sarah'].title() + 
     ".")
6.3遍历字典
  • 遍历所有的键—值对 ----for k, v in user_0.items()
    键—值对的返回顺序也与存储顺序不同。Python不关心键—值对的存 储顺序,而只跟踪键和值之间的关联关系
  • 遍历字典中的所有键 —for name in favorite_languages.keys():
  • 按顺序遍历字典中的所有键 :函 数sorted()来获得按特定顺序排列的键列表的副本—for name in sorted(favorite_languages.keys()):
  • 遍历字典中的所有值 —for language in set(favorite_languages.values()): 剔除重复项,可使用集合(set)。
6.4嵌套
  • 示例;三嵌套
alien_0 = {'color': 'green', 'points': 5} 
alien_1 = {'color': 'yellow', 'points': 10}
alien_2 = {'color': 'red', 'points': 15} 
 
aliens = [alien_0, alien_1, alien_2] 
 
for alien in aliens:
    print(alien) 
  • 在字典中存储列表
pizza = {     
    'crust': 'thick',
    'toppings': ['mushrooms', 'extra cheese'],     
    } 
  • 在字典中存储字典
users = {    
    'aeinstein': {         
        'first': 'albert',         
        'last': 'einstein',         
        'location': 'princeton',         
        }, 
 
    'mcurie': {  
        'first': 'marie',  
        'last': 'curie',     
        'location': 'paris',
        }, 
 
    } 
7用户输入和while循环 7.1 input()
  • 示例
message = input("Tell me something, and I will repeat it back to you: ") 
  • 创建多行字符串的方式。第1行将消息的前半部分存储在变量prompt中; 在第2行中,运算符+=在存储在prompt中的字符串末尾附加一个字符串
  • 使用int()来获取数值输入 —age = int(age)
  • 求模运算符 — 6 % 3
    如果一个数可被另一个数整除,余数就为0,因此求模运算符将返回0。你可利用这一点来判 断一个数是奇数还是偶数:
7.2while 循环
  • 示例
current_number = 1 
while current_number <= 5:
    print(current_number)
    current_number += 1 
  • 让用户选择何时退出 如果没有可供比较的东西,Python将无法继续运行程序。为解决这个问题, 我们必须给变量message指定一个初始值
prompt = "nTell me something, and I will repeat it back to you:" 
prompt += "nEnter 'quit' to end the program. "  
message = ""  
while message != 'quit':     
    message = input(prompt)     
    print(message) 
  • 使用标志 :,可定义一个变量,用于判断整个程序是否处于 活动状态。这个变量被称为标志.e.g:可让程序在标志为True时继续运 行,并在任何事件导致标志的值为False时让程序停止运行
 active = True  
 while active:    
    message = input(prompt)           
    if message == 'quit':         
        active = False      
    else:        
    print(message)
  • 使用break 退出循环
    -在任何Python循环中都可使用break语句。例如,可使用break语句来退出遍历列表或字典 的for循环。
while True:    
    city = input(prompt) 
    
    if city == 'quit':         
        break 
    else:         
        print("I'd love to go to " + city.title() + "!") 
  • 在循环中使用 continue
    • 要返回到循环开头,并根据条件测试结果决定是否继续执行循环,可使用continue语句
current_number = 0 
while current_number < 10:      
    current_number += 1   
    if current_number % 2 == 0:       
        continue         
        
    print(current_number) 
  • 避免无限循环
    • 可按Ctrl + C,也可关闭显示程序输出的终端窗口。
    • 确认程序至少有一个这样的地方能让循环条件为False或让break 语句得以执行。
7.3使用while 循环来处理列表和字典
  • 在列表之间移动元素 pop
# 首先,创建一个待验证用户列表 
#  和一个用于存储已验证用户的空列表 
un/confirm/ied_users = ['alice', 'brian', 'candace'] /confirm/ied_users = [] 
 
# 验证每个用户,直到没有未验证用户为止
#  将每个经过验证的列表都移到已验证用户列表中  
while un/confirm/ied_users: 
    current_user = un/confirm/ied_users.pop()         
    
    print("Verifying user: " + current_user.title())   
    /confirm/ied_users.append(current_user)  
    
# 显示所有已验证的用户 
print("nThe following users have been /confirm/ied:") 
for /confirm/ied_user in /confirm/ied_users:                     
    print(/confirm/ied_user.title()) 
- 分析:
函数pop()以每次一个的方式从列表un/confirm/ied_users末尾删除未验证的用户。由于Candace位于列表un/confirm/ied_users末尾,因此其名字将首先被删除、存储到变量current_user中并加入到列表/confirm/ied_users中
  • 删除包含特定值的所有列表元素—remove()来删除列表中的特定值
  • 使用用户输入来填充字典 —
responses = {} 
 
# 设置一个标志,指出调查是否继续 
polling_active = True 
 
while polling_active:    
    # 提示输入被调查者的名字和回答      
    name = input("nWhat is your name? ")    
    response = input("Which mountain would you like to climb someday? ")          
    
    # 将答卷存储在字典中      
    responses[name] = response     
    
    # 看看是否还有人要参与调查      
    repeat = input("Would you like to let another person respond? (yes/ no) ")    
    if repeat == 'no':        
        polling_active = False          
    # 调查结束,显示结果 
    print("n--- Poll Results ---") 
    for name, response in responses.items():                
        print(name + " would like to climb " + response + ".") 
- 注意:首先定义了一个空字典(responses),并设置了一个标志(polling_active),用于指出调查是否继续
8函数 8.1定义函数
  • 向函数传递信息
def greet_user(username):    
    """显示简单的问候语""" 
    print("Hello, " + username.title() + "!")
greet_user('jesse')
  • 实参和形参
    • 变量username是一个形参——函数完成其工作所需的一项信 息
    • 值’jesse’是一个实参。实参是调用函数时传递给函数的信 息
8.2 传递实参
  • 位置实参
def describe_pet(animal_type, pet_name):  
    """显示宠物的信息"""    
    print("nI have a " + animal_type + ".")     
    print("My " + animal_type + "'s name is " + pet_name.title() + ".")       
describe_pet('hamster', 'harry'
- 1. 调用函数多次 
- 2. 位置实参的顺序很重要 
  • 关键字实参是传递给函数的名称—值对
def describe_pet(animal_type, pet_name):     """显示宠物的信息"""    
    print("nI have a " + animal_type + ".")     
    print("My " + animal_type + "'s name is " + pet_name.title() + ".")      
describe_pet(animal_type='hamster', pet_name='harry') 
  • 默认值
    • 使用默认值时,在形参列表中必须先列出没有默认值的形参,再列出有默认值的实参。这让Python依然能够正确地解读位置实参。
    • 默认值放定义函数参数的最后
  • 等效的函数调用
  • 避免实参错误
8.3返回值
  • 接受名和姓并返回整洁的姓名
def get_formatted_name(first_name, last_name):     
    """返回整洁的姓名"""    
    full_name = first_name + ' ' + last_name    
    return full_name.title() 
 
musician = get_formatted_name('jimi', 'hendrix') print(musician) 
  • 让实参变成可选的
    • 可给实参middle_name指定一个默认值——空字符串,并在用 户没有提供中间名时不使用这个实参
  • 返回字典
def build_person(first_name, last_name):     
    """返回一个字典,其中包含有关一个人的信息"""      
    person = {'first': first_name, 'last': last_name}      
    return person 
 
musician = build_person('jimi', 'hendrix')  print(musician) 
  • 结合使用函数和 while 循环
8.4传递列表
  • 将列表传递给函数后,函数就可对其进行修改。在函数中对这个列表所做的任何修改都是永久性的
# 首先创建一个列表,其中包含一些要打印的设计 unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron'] completed_models = [] 
 
# 模拟打印每个设计,直到没有未打印的设计为止 
#  打印每个设计后,都将其移到列表completed_models中
while unprinted_designs:    
    current_design = unprinted_designs.pop()   
    
    #模拟根据设计制作3D打印模型的过程    
    print("Printing model: " + current_design) 
    completed_models.append(current_design)  
    
# 显示打印好的所有模型 
print("nThe following models have been printed:")
for completed_model in completed_models:  
    print(completed_model) 
- 这个程序还演示了这样一种理念,即每个函数都应只负责一项具体的工作。第一个函数打印 每个设计,而第二个显示打印好的模型;这优于使用一个函数来完成两项工作
  • 禁止函数修改列表
    • 切片表示法[:]创建列表的副本
    • 在print_models.py中,如果不想清空未打印的设计列表, 可像下面这样调用print_models():— print_models(unprinted_designs[:], completed_models)
8.5传递任意数量的实参
  • 下面的函数只有一个形参*toppings,但不管调用语句提供了多少实参,这个形参都将它们 统统收入囊中
def make_pizza(*toppings):    
    """打印顾客点的所有配料"""     
    print(toppings)       
    
make_pizza('pepperoni') 
make_pizza('mushrooms', 'green peppers', 'extra cheese')
  • 结合使用位置实参和任意数量实参
    • 要让函数接受不同类型的实参,必须在函数定义中将接纳任意数量实参的形参放在后
  • 使用任意数量的关键字实参
    • 形参**user_info中的两个星号让Python创建一个名为user_info的空字典,并将收到的所 有名称—值对都封装到这个字典中
8.6将函数存储在模块中
  • 导入整个模块— import pizza
  • 导入特定的函数 —from module_name import function_name
  • 使用as 给函数指定别名 — from module_name import function_name as fn
  • 导入模块中的所有函数—from pizza import *
8.7 函数编写指南
  • 应给函数指定描述性名称,且只在其中使用小写字母和下划线
  • 每个函数都应包含简要地阐述其功能的注释
  • 对于函数调用中的关键字实参,也应遵循这种约定
  • 议代码行的长度不要超过79字符
  • 导致函数定义的长度超过了79字符,可在函数定义中输入左括号后按回车键,并在下一行按两次Tab键
9 类 9.1创建和使用类
  • 示例
class Dog():     
    """一次模拟小狗的简单尝试"""          
    def __init__(self, name, age):   
         """初始化属性name和age"""      
        self.name = name      
        self.age = age        
     def sit(self):      
        """模拟小狗被命令时蹲下"""        
        print(self.name.title() + " is now sitting.") 
 
    def roll_over(self):  
        """模拟小狗被命令时打滚"""   
        print(self.name.title() + " rolled over!") 
- 根据约定,在Python中,首字母大写的名称指的是类。
- 方法__init__() 
    - 类中的函数称为方法;你前面学到的有关函数的一切都适用于方法
    - 每当你根据Dog类创建新实 例时,Python都会自动运行它
    - 开头和末尾各有两个下划线,这是一种约 定,旨在避免Python默认方法与普通方法发生名称冲突
  • 根据类创建实例
      1. 访问属性—my_dog.name
      1. 调用方法
      class Dog():  
      -snip -- 
      
      my_dog = Dog('willie', 6) my_dog.sit() my_dog.roll_over()   
      
      1. 创建多个实例
      class Dog():    
      -snip -- 
      
      my_dog = Dog('willie', 6) 
      your_dog = Dog('lucy', 3) 
      
9.2 使用类和实例
  • Car 类
class Car():  
    """一次模拟汽车的简单尝试""" 
 
    def __init__(self, make, model, year):         
        """初始化描述汽车的属性"""       
        self.make = make        
        self.model = model        
        self.year = year            
        
    def get_descriptive_name(self):  
        """返回整洁的描述性信息"""    
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model        
        return long_name.title()      
        
my_new_car = Car('audi', 'a4', 2016)
print(my_new_car.get_descriptive_name()) 
  • 给属性指定默认值 self.odometer_reading = 0
  • 修改属性的值
      1. 直接修改属性—my_new_car.odometer_reading = 23
      1. 通过方法修改属性的值— def update_odometer(self, mileage):
      1. 通过方法对属性的值进行递增 —def increment_odometer(self, miles):
9.3 继承
  • 子类的方法__init__()
  • 给子类定义属性和方法
class Car():    
-snip --         
 
class ElectricCar(Car):   
    """Represent aspects of a car, specific to electric vehicles.""" 
 
    def __init__(self, make, model, year):
        """         
        电动汽车的独特之处    
        初始化父类的属性,再初始化电动汽车特有的属性       
        """       
        super().__init__(make, model, year)          
        self.battery_size = 70     
        
     def describe_battery(self):   
     """打印一条描述电瓶容量的消息"""   
     print("This car has a " + str(self.battery_size) + "-kWh battery.") 
 
my_tesla = ElectricCar('tesla', 'model s', 2016) 
print(my_tesla.get_descriptive_name()) 
my_tesla.describe_battery() 
  • 重写父类的方法
def ElectricCar(Car):  
    -snip -- 
 
    def fill_gas_tank():     
        """电动汽车没有油箱"""    
        print("This car doesn't need a gas tank!") 
  • 将实例用作属性 ??
9.4导入类
  • 导入单个类—from car import Car
  • 在一个模块中存储多个类
  • 从一个模块中导入多个类 —from car import Car, ElectricCar
  • 导入整个模块 — import car
  • 导入模块中的所有类 —from module_name import *
  • 在一个模块中导入另一个模块 —
9.5 Python标准库 9.6 类编码风格 10.文件和异常 10.1 从文件中读取数据
  • 读取整个文件
with open('pi_digits.txt') as file_object: 
    contents = file_object.read() 
    print(contents) 
  • 文件路径

    • 相对路径
    • 绝对路径
  • 逐行读取

  • 创建一个包含文件各行内容的列表

  • 使用文件的内容

  • 包含一百万位的大型文件

10.2 写入文件
filename = 'programming.txt' 
 
with open(filename, 'w') as file_object:      
    file_object.write("I love programming.")
  • 写入多行
filename = 'programming.txt' 
 
with open(filename, 'w') as file_object:  
    file_object.write("I love programming.n")     
    file_object.write("I love creating new games.n") 
  • 附加到文件----with open(filename, ‘a’) as file_object:
10.3 异常
  • 处理ZeroDivisionError 异常
  • 使用try-except 代码块 —用户看到的是一条友好的错误消息,而 不是traceback
  • 使用异常避免崩溃
  • else 代码块
  • 处理FileNotFoundError 异常
  • 分析文本 —
title = "Alice in Wonderland" 
title.split() 
['Alice', 'in', 'Wonderland']  
  • 使用多个文件
def count_words(filename):   
-snip -- 
 
filenames = ['alice.txt', 'siddhartha.txt', 'moby_dick.txt', 'little_women.txt']
for filename in filenames:  
    count_words(filename)
  • 失败时一声不吭
  • 决定报告哪些错误
10.4 存储数据
  • 使用json.dump()和 json.load()
  • 保存和读取用户生成的数据
  • 重构
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/619171.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号