您的位置:首页 > 科技 > IT业 > 成人自考本科_专业团队图片原图_手机网站制作平台_sem是什么意思的缩写

成人自考本科_专业团队图片原图_手机网站制作平台_sem是什么意思的缩写

2025/6/21 15:15:16 来源:https://blog.csdn.net/p6448777/article/details/147478521  浏览:    关键词:成人自考本科_专业团队图片原图_手机网站制作平台_sem是什么意思的缩写
成人自考本科_专业团队图片原图_手机网站制作平台_sem是什么意思的缩写

Python编程:从入门到实践!
第一章:变量和简单数据类型
配置快捷键,这三个非常常用
undo ctrl+z
redo ctrl+y
format ctrl+q
*******************************************************************************************************************************************
第三章:列表
*******************************************************************************************************************************************
使用sorted() 按字母顺序打印这个列表,同时不要修改它。
再次打印该列表,核实排列顺序未变。
使用sorted() 按与字母顺序相反的顺序打印这个列表,同时不要修改它。
再次打印该列表,核实排列顺序未变。
使用reverse() 修改列表元素的排列顺序。打印该列表,核实排列顺序确实变了。
使用reverse() 再次修改列表元素的排列顺序。打印该列表,核实已恢复到原来的排列顺序。
使用sort() 修改该列表,使其元素按字母顺序排列。打印该列表,核实排列顺序确实变了。
使用sort() 修改该列表,使其元素按与字母顺序相反的顺序排列。打印该列表,核实排列顺序确实变了。
第四章:操作列表
*******************************************************************************************************************************************
1、下面示例表明了friend_foods = my_foods[:]  # 切片这个和直接相等还是不一样的。切片是两个对象,而=是一个对象
my_foods = ["苹果", "香蕉"]
friend_foods = my_foods[:]  # 这个和直接相等还是不一样的
print(friend_foods)
print(my_foods == friend_foods)
my_foods.append("橘子")
friend_foods.append("桃子")
print(f"{my_foods}---vs---{friend_foods}")
print(my_foods == friend_foods)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
2、元组(不可变的列表)
列表非常适合用于存储在程序运行期间可能变化的数据集。列表是可以修改的,这对处理网站的用户列表或游戏中的角色列表至关重要。
然而,有时候你需要创建一系列不可修改的元素,元组可以满足这种需求。Python将不能修改的值称为不不可可变变的的 
,而不可变的列表被称为元组 。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
3、代码格式
第五章:if语句
*******************************************************************************************************************************************
1、PYTHON 判断对大小写敏感
cars = ['audi', 'bmw', 'subaru', 'toyota']
for car in cars:
    if car != 'bmw':    #if car == 'bmw':
        print(car.upper())
    else:
        print(car.title())
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
2、组合条件判断
你可能想同时检查多个条件,例如,有时候你需要在两个条件都为True 时才执行相应的操作,而有时候你只要求一个条件为True 时就执行相应的操作。
在这些情况下,关键字and 和or 可助你一臂之力。
# 为改善可读性,可将每个测试都分别放在一对括号内,但并非必须这样做。如果你使用括号,测试将类似于下面这样:
age = 10
if (age > 0) and (age < 15):
    print("在合理范围")

# 为改善可读性,可将每个测试都分别放在一对括号内,但并非必须这样做。如果你使用括号,测试将类似于下面这样:
age = 10
if (age > 15) or (age < 0):
    print("在合理范围")
else:
    print("不在合理范围")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
3、检查特定元素是否在列表
# 检查查特特定定值值是是否否包包含含在在列列表表中
car_list = ["宝马", "大众", "奥迪"]
if "宝马" in car_list:
    print("在列表中")

# 检查查特特定定值值是是否否包包含含在在列列表表中
car_list = ["宝马", "大众", "奥迪"]
if "宝马" not in car_list:
    print("不在列表")
else:
    print("在的 你还找")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
4、布尔表达式
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.")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
5、列表循环加判断
requested_toppings = ["apple", "orange"]
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?")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
6、综合判断
user_list = ["admin", "tom", "jack"]
if user_list:
    for temp in user_list:
        if temp == "admin":
            print(f"{temp} welcome")
        else:
            print(f"hello {temp}")
else:
    print("we need users")
第六章:字典
*******************************************************************************************************************************************
1、 与大多数编程概念一样,要熟练使用字典,也需要一段时间的练习。使用字典一段时间后,你就会明白为何它们能够高效地模拟现实世界中的情形。
alien = {'color': 'green', 'points': 5}
print(alien["color"])
2、字典是一种动态结构,可随时在其中添加键—值对。要添加键—值对,可依次指定字典名、用方括号括起的键和相关联的值。和JSON好像,这就是PY和JSON的方便。
alien_0 = {'color': 'green', 'points': 5}
print(alien_0)
alien_0['x_position'] = 0
alien_0['y_position'] = 25
print(alien_0)

{'color': 'green', 'points': 5}
{'color': 'green', 'points': 5, 'x_position': 0, 'y_position': 25}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
2、修改字典
alien_0 = {'color': 'green'}
print(alien_0)
alien_0['color'] = 'yellow'
print(alien_0)
{'color': 'green'}
{'color': 'yellow'}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
3、删除键—值对
alien_0 = {'color': 'green', 'points': 5}
print(alien_0)
del alien_0['points']
print(alien_0)
{'color': 'green', 'points': 5}
{'color': 'green'}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
4、遍历字典  和JSON相关 又类似JAVA---Map
users = {
    'username': 'efermi',
    'first': 'enrico',
    'last': 'fermi',
}
for k, v in users.items():
    print("\nKey: " + k)
    print("Value: " + v)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
5、根据key查询value比Map简单
users = {
    'username': 'efermi',
    'first': 'enrico',
    'last': 'fermi',
}
for k, v in users.items():
    print("\nKey: " + k)
    print("Value: " + v)

print(users["username"]) #根据key查询value比Map简单
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
6、值去重后再遍历打印,通过对包含重复元素的列表调用set() ,可让Python找出列表中独一无二的元素,并使用这些元素来创建一个集合。
favorite_languages = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python',
}
print("The following languages have been mentioned:")
for language in set(favorite_languages.values()):  # set让值去重了
    print(language.title())  # 获取单个值是title
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&    
7、嵌套。有时候,需要将一系列字典存储在列表中,或将列表作为值存储在字典中,这称为嵌套 。你可以在列表中嵌套字典、在字典中嵌套列表甚至在字典中嵌套字典。正如下面的示例 将演示的,嵌套是一项强大的功能。 这才符合真正的JSON!!! 59页
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&    
8、切片,并将这些字典存储在一个名为users 的列表中。在这个列表中,所有字典的结构都相同,因此你可以遍历这个列表,并以相同的方式处理其中的每个字典。
# 创建一个用于存储外星人的空列表
aliens = []
# 创建30个绿色的外星人
for alien_number in range(0, 30):
    new_alien = {'color': 'green', 'points': 5, 'speed': 'slow'}
    aliens.append(new_alien)
for alien in aliens[0:3]: # 用到了切片
    if alien['color'] == 'green':
        alien['color'] = 'yellow'
        alien['speed'] = 'medium'
        alien['points'] = 10
# 显示前五个外星人
for alien in aliens[0:5]:
    print(alien)
print("...")

多次判断
# 创建一个用于存储外星人的空列表
aliens = []
# 创建30个绿色的外星人
for alien_number in range(0, 30):
    new_alien = {'color': 'green', 'points': 5, 'speed': 'slow'}
    aliens.append(new_alien)
for alien in aliens[0:3]:
    if alien['color'] == 'green':
        alien['color'] = 'yellow'
        alien['speed'] = 'medium'
        alien['points'] = 10
    elif alien['color'] == 'yellow':
        alien['color'] = 'red'
        alien['speed'] = 'fast'
        alien['points'] = 15
# 显示前五个外星人
for alien in aliens[0:5]:
    print(alien)
print("...")

for alien in aliens[0:3]:
    if alien['color'] == 'green':
        alien['color'] = 'yellow'
        alien['speed'] = 'medium'
        alien['points'] = 10
    elif alien['color'] == 'yellow':
        alien['color'] = 'red'
        alien['speed'] = 'fast'
        alien['points'] = 15
# 显示前五个外星人
for alien in aliens[0:5]:
    print(alien)
print("...")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
9、在字典中存储列表
# 存储所点比萨的信息
pizza = {
    'crust': 'thick',
    'toppings': ['mushrooms', 'extra cheese'],
}
# 概述所点的比萨,字典中列表的遍历
print("You ordered a " + pizza['crust'] + "-crust pizza " +
      "with the following toppings:")
for topping in pizza['toppings']:
    print("\t" + topping)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
10、k v组合遍历
favorite_languages = {
    'jen': ['python', 'ruby'],
    'sarah': ['c'],
    'edward': ['ruby', 'go'],
    'phil': ['python', 'haskell'],
}
for name, languages in favorite_languages.items():
    print("\n" + name.title() + "'s favorite languages are:")
    for language in languages:
        print("\t" + language.title())
注意:列表和字典的嵌套层级不应太多。如果嵌套层级比前面的示例多得多,很可能有更简单的解决问题的方案
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
11、只有字典才可以这么灵活的使用
users = {
    'aeinstein': {
        'first': 'albert',
        'last': 'einstein',
        'location': 'princeton',
    },
    'mcurie': {
        'first': 'marie',
        'last': 'curie',
        'location': 'paris',
    },
}
for username, user_info in users.items():
    print("\nUsername: " + username)
    full_name = user_info['first'] + " " + user_info['last']
    location = user_info['location']
    print("\tFull name: " + full_name.title())
    print("\tLocation: " + location.title())
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
第七章:用户输入和while循环
*******************************************************************************************************************************************
1、获取用户输入。
user_input = input("请输入些内容:")
print(user_input)

user_input = input("你多大了?")
print(user_input)
if int(user_input) > 18:
    print("你成年了")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
2、求模运算符不会指出一个数是另一个数的多少倍,而只指出余数是多少
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
2、while循环简介
current_number = 1
while current_number <= 9:
    print(current_number)
    current_number = current_number + 1

user_input = ""
while user_input != "退出":
    user_input = input("请输入信息:")
    print(f"你输入的信息是:{user_input}")

user_input = ""
while user_input != "退出":
    user_input = input("请输入信息:")
    if user_input != "退出":
        print(f"你输入的信息是:{user_input}")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
3、交通信号灯
在要求很多条件都满足才继续运行的程序中,可定义一个变量,用于判断整个程序是否处于活动状态。这个变量被称为标标志志 ,充当了程序的交通信号灯。你可让程序在标志 为True 时继续运行,并在任何事件导致标志的值为False 时让程序停止运行。这样,在while 语句中就只需检查一个条件——标志的当前值是否为True ,并将所有测试(是 否发生了应将标志设置为False 的事件)都放在其他地方,从而让程序变得更为整洁。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
4、使用break 退出循环
prompt = "\nPlease enter the name of a city you have visited:"
prompt += "\n(Enter 'quit' when you are finished.) "
while True:
    city = input(prompt)
    if city == 'quit':
        break
    else:
        print("I'd love to go to " + city.title() + "!")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 65页
5、continue的使用
current_number = 0
while current_number < 10:
    current_number += 1
    if current_number % 2 == 0:
        continue
    print(current_number)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
6、while循环来处理列表和字典
for 循环是一种遍历列表的有效方式,但在for 循环中不应修改列表,否则将导致Python难以跟踪其中的元素。要在遍历列表的同时对其进行修改,可使用while 循环。通过将while 循环同列表和字典结合起来使用,可收集、存储并组织大量输入,供以后查看和显示。
# 首先,创建一个待验证用户列表
# 和一个用于存储已验证用户的空列表
unconfirmed_users = ['alice', 'brian', 'candace']
confirmed_users = []
# 验证每个用户,直到没有未验证用户为止
# 将每个经过验证的列表都移到已验证用户列表中
while unconfirmed_users:
    current_user = unconfirmed_users.pop()  # 关键方法
    print("Verifying user: " + current_user.title())
    confirmed_users.append(current_user)  # 关键方法
    # 显示所有已验证的用户
    print("\nThe following users have been confirmed:")
for confirmed_user in confirmed_users:
    print(confirmed_user.title())
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
7、假设你有一个宠物列表,其中包含多个值为'cat' 的元素。要删除所有这些元素,可不断运行一个while 循环,直到列表中不再包含值'cat'
pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']
print(pets)
while 'cat' in pets:  # 列表可以用while xxx in xxx_list
    pets.remove('cat')
    print(pets)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
8、问卷调研
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 + ".")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
9、PYTHON要重点区分 xxx_list  xxx_dict 两种类型用法差距很大
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
10、在本章中,你学习了:如何在程序中使用input() 来让用户提供信息;如何处理文本和数字输入,以及如何使用while 循环让程序按用户的要求不断地运行;多种控制while 循环流程的方式:设置活动标志、使用break 语句以及使用continue 语句;如何使用while 循环在列表之间移动元素,以及如何从列表中删除所有包含特定值的元素;如何结合使用while 循环和字典。
第八章:函数
*******************************************************************************************************************************************
1、函数
def say_hello():
    print("hello")


say_hello()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
2、传参
def say_hello(name):
    print("hello---" + name)


say_hello("tom")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
3、关键字实参
def say_hello(name):
    print("hello---" + name)


# 关键字实参
say_hello(name="tom")
say_hello(name="rose")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
4、参数默认值
def describe_pet(pet_name, animal_type='dog'):
    """显示宠物的信息"""
    print("\nI have a " + animal_type + ".")
    print("My " + animal_type + "'s name is " + pet_name.title() + ".")


describe_pet(pet_name='willie')
describe_pet(pet_name='willie', animal_type="cat")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
5、用哪种调用方式无关紧要,只要函数调用能生成你希望的输出就行。使用对你来说最容易理解的调用方式即可。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
6、返回值
def sum_number(val_1, val_2):
    return val_1 + val_2


res = sum_number(1, 2)
print(res)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
7、实参可选
有时候,需要让实参变成可选的,这样使用函数的人就只需在必要时才提供额外的信息。可使用默认值!!!来让实参变成可选的。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
8、返回的数据类型
函数可返回任何类型的值,包括列表和字典等较复杂的数据结构。
def build_person(first_name, last_name):
    """返回一个字典,其中包含有关一个人的信息"""
    person_dict = {'first': first_name, 'last': last_name}
    return person_dict


musician = build_person('jimi', 'hendrix')
print(musician)

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
9、循环+函数
def get_formatted_name(first_name, last_name):
    """返回整洁的姓名"""

    full_name = first_name + ' ' + last_name
    return full_name.title()


# 这是一个无限循环!
while True:
    print("\nPlease tell me your name:")
    f_name = input("First name: ")
    l_name = input("Last name: ")
    formatted_name = get_formatted_name(f_name, l_name)
    print("\nHello, " + formatted_name + "!")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
10、传递复杂参数
你经常会发现,向函数传递列表很有用,这种列表包含的可能是名字、数字或更复杂的对象(如字典)。将列表传递给函数后,函数就能直接访问其内容。下面使用函数来提高处理列表的效率。
def greet_users(names):
    """向列表中的每位用户都发出简单的问候"""
    for name in names:
        msg = "Hello, " + name.title() + "!"
        print(msg)


name_list = ['hannah', 'ty', 'margot']
greet_users(name_list) # 传递列表
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
11、在函数中修改列表
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
12、创建列表副本
name_list = ["小明", "小强"]
print(name_list[:])
切片表示法[:] 创建列表的副本。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
13、传递任意数量的实参
def make_pizza(*toppings):
    """打印顾客点的所有配料"""
    print(toppings)


make_pizza('pepperoni')
make_pizza('mushrooms', 'green peppers', 'extra cheese')
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
14、实参+任意参数
def make_pizza(size, *toppings):
    """概述要制作的比萨"""
    print("\nMaking a " + str(size) +
          "-inch pizza with the following toppings:")
    for topping in toppings:
        print("- " + topping)


make_pizza(16, 'pepperoni')
make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese')
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
15、任意数量的关键字实参
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
16、将函数存储在模块中
将函数存储在被称为模模块块 的独立文件中,再将模块导导入入 到主程序中。import 语句允许在当前运行的程序文件中使用模块中的代码。
目前看没必要!
文件的的import和函数的引入使用,配置个阿里云的事情
def say_hello(): #文件名为my_def
    print("Hello")

import my_def # 使用先引入,然后文件名.方法名

my_def.say_hello()

# 还可以直接引入方法,这么引入,我觉得简单点,直接引入包名,或者自动引入
from my_def import say_hello

say_hello()

导入模块中的所有函数:
from pizza import *
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
17、函数编写规范
编写函数时,需要牢记几个细节。应给函数指定描述性名称,且只在其中使用小写字母和下划线。描述性名称可帮助你和别人明白代码想要做什么。给模块命名时也应遵循上述约定。(这个和JS是一个套路...)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
18、总结
你学习了:如何编写函数,以及如何传递实参,让函数能够访问完成其工作所需的信息;如何使用位置实参和关键字实参,以及如何接受任意数量的实参;显示输出 的函数和返回值的函数;如何将函数同列表、字典、if 语句和while 循环结合起来使用。你还知道了如何将函数存储在被称为模模块块 的独立文件中,让程序文件更简单、更易于 理解。最后,你学习了函数编写指南,遵循这些指南可让程序始终结构良好,并对你和其他人来说易于阅读。

第九章:类
*******************************************************************************************************************************************
1、面向对象编程 是最有效的软件编写方法之一
class Dog():
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def cry(self):
        print(f"{self.name}---cry")

    def roll_over(self):
        print(f"{self.name}---roll over")


dog_1 = Dog(name="小狗", age=2)
dog_1.cry()
dog_1.roll_over()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
2、我们创建了两条小狗,它们分别名为Willie和Lucy。每条小狗都是一个独立的实例,有自己的一组属性,能够执行相同的操作。
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())
my_new_car_2 = Car('dazhong', 'sagatar', 2024)
print(my_new_car_2.get_descriptive_name())
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
3、给属性赋初始值
class Car():
    def __init__(self, make, model, year):
        """初始化描述汽车的属性"""
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0

    def get_descriptive_name(self):
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

    def read_odometer(self):
        """打印一条指出汽车里程的消息"""
        print("This car has " + str(self.odometer_reading) + " miles on it.")


my_new_car = Car('audi', 'a4', 2016)
print(my_new_car.get_descriptive_name())
my_new_car.read_odometer()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
4、修改属性值:直接通过实例进行修改;通过方法进行设置;通过方法进行递增(增加特定的值)。
my_new_car.odometer_reading = 23

def update_odometer(self, mileage):
    """将里程表读数设置为指定的值"""
    self.odometer_reading = mileage
my_new_car.update_odometer(30)

通过方法对属性的值进行递增
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
5、继承,感觉也只有在继承面板游戏开发的时候才实用点...
编写类时,并非总是要从空白开始。如果你要编写的类是另一个现成类的特殊版本,可使用继继承承 。一个类继继承承 另一个类时,它将自动获得另一个类的所有属性和方法;原有的类称为父父类类 ,而新类称为子子类类 。子类继承了其父类的所有属性和方法,同时还可以定义自己的属性和方法。
class Car():
    """一次模拟汽车的简单尝试"""

    def __init__(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0

    def get_descriptive_name(self):
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

    def read_odometer(self):
        print("This car has " + str(self.odometer_reading) + " miles on it.")

    def update_odometer(self, mileage):
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")

    def increment_odometer(self, miles):
        self.odometer_reading += miles


class ElectricCar(Car): # 继承的写法
    """电动汽车的独特之处"""

    def __init__(self, make, model, year):
        """初始化父类的属性"""
        super().__init__(make, model, year)  # 关键动作


my_tesla = ElectricCar('tesla', 'model s', 2016)
print(my_tesla.get_descriptive_name())
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
6、子类可以继承父类属性+方法,也可以自定义自己的方法
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
7、子类重写父类方法
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
8、导入类
随着你不断地给类添加功能,文件可能变得很长,即便你妥善地使用了继承亦如此。为遵循Python的总体理念,应让文件尽可能整洁。为在这方面提供帮助,Python允许你将类存储在模块中,然后在主程序中导入所需的模块。
"""一个可用于表示汽车的类"""


class Car():
    """一次模拟汽车的简单尝试"""

    def __init__(self, make, model, year):
        """初始化描述汽车的属性"""
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0

    def get_descriptive_name(self):
        """返回整洁的描述性名称"""
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

    def read_odometer(self):
        """打印一条消息,指出汽车的里程"""
        print("This car has " + str(self.odometer_reading) + " miles on it.")

    def update_odometer(self, mileage):
        """ 将里程表读数设置为指定的值
        拒绝将里程表往回拨
        """
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")

    def increment_odometer(self, miles):
        """将里程表读数增加指定的量"""
        self.odometer_reading += miles

import car

car_1 = car.Car(make="W", model="S", year=2014)
print(car_1.get_descriptive_name())
car_1.read_odometer()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
9、在在一个模块中存储多个类
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
10、导入整个模块 : 这个是最好用的
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
11、大佬的开发思维
一开始应让代码结构尽可能简单。先尽可能在一个文件中完成所有的工作,确定一切都能正确运行后,再将类移到独立的模块中。如果你喜欢模块和文件的交互方式,可在项目开始时就尝试将类存储到模块中。先找出让你能够编写出可行代码的方式,再尝试让代码更为组织有序。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
12、Python标准库
字典让你能够将信息关联起来,但它们不记录你添加键—值对的顺序。要创建字典并记录其中的键—值对的添加顺序,可使用模块collections 中的OrderedDict 类。
from collections import OrderedDict

favorite_languages = OrderedDict()  # 关键动作  主要是怎么插入 怎么展示 这个顺序 并不是排序

favorite_languages['jen'] = 'python'
favorite_languages['phil'] = 'python'
favorite_languages['sarah'] = 'c'
favorite_languages['edward'] = 'ruby'

for name, language in favorite_languages.items():
    print(name.title() + "'s favorite language is " +
          language.title() + ".")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
13、产生随机数
from random import randint

x = randint(1, 6)
print(x)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
14、类的命名规则
类名应采用驼峰命名法 ,即将类名中的每个单词的首字母都大写,而不使用下划线。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
15、小结:
如何编写类;如何使用属性在类中存储信息,以及如何编写方法,以让类具备所需的行为;如何编写方法__init__() ,以便根据类创建包含所需属性的 实例。你见识了如何修改实例的属性——包括直接修改以及通过方法进行修改。你还了解了:使用继承可简化相关类的创建工作;将一个类的实例用作另一个类的属性可让类更 简洁。 你了解到,通过将类存储在模块中,并在需要使用这些类的文件中导入它们,可让项目组织有序。你学习了Python标准库,并见识了一个使用模块collections 中 的OrderedDict 类的示例。最后,你学习了编写类时应遵循的Python约定。
*******************************************************************************************************************************************
第十章:文件与异常
*******************************************************************************************************************************************
1、文件读取
with open("./in.txt", encoding="utf-8") as in_txt:
    res = in_txt.read()
    print(res)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
2、逐行读取
# coding:utf8

with open("./in.txt", encoding="utf-8") as in_txt:
    for line in in_txt:
        print(line, end="")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
3、创建一个列表存储文件的每行内容
filename = 'in.txt'
with open(filename, encoding="utf8") as file_object:
    lines = file_object.readlines()
for line in lines:
    print(line.rstrip())

注意:读取文本文件时,Python将其中的所有文本都解读为字符串。如果你读取的是数字,并要将其作为数值使用,就必须使用函数int() 将其转换为整数,或使用 函数float() 将其转换为浮点数。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
4、对于你可处理的数据量,Python没有任何限制;只要系统的内存足够多,你想处理多少数据都可以。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
5、写入数据
保存数据的最简单的方式之一是将其写入到文件中。通过将输出写入文件,即便关闭包含程序输出的终端窗口,这些输出也依然存在:你可以在程序结束运行后查看这些输出,可与别人分享输出文件,还可编写程序来将这些输出读取到内存中并进行处理。
with open("./out.txt", mode="w", encoding="utf8") as out_txt:
    out_txt.write("爱我中华")
如果你要写入的文件不存在,函数open() 将自动创建它。然而,以写入('w' )模式打开文件时千万要小心,因为如果指定的文件已经存在,Python将在返回文件对象前清空该文件。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
6、追加数据用mode="a"
with open("./out.txt", mode="a", encoding="utf8") as out_txt:
    out_txt.write("爱我中华")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
7、可指定读读取取模模式式 ('r' )、写写入入模模式式 ('w' )、附附加加模模式式 ('a' )或让你能够读取和写入文件的模式('r+' )。如果你省略了模式实参,Python将以默认的只读模式打 开文件。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
8、如果你要写入的文件不存在,函数open() 将自动创建它。然而,以写入('w' )模式打开文件时千万要小心,因为如果指定的文件已经存在,Python将在返回文件对象前清空 该文件。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
9、需要手动指定\n换行
with open("./out.txt", mode="w", encoding="utf8") as out_txt:
    out_txt.write("爱我中华\n")
    out_txt.write("五星红旗")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
10、异常
Python使用被称为异常 的特殊对象来管理程序执行期间发生的错误。每当发生让Python不知所措的错误时,它都会创建一个异常对象。如果你编写了处理该异常的代码,程序将继 续运行;如果你未对异常进行处理,程序将停止,并显示一个traceback,其中包含有关异常的报告。
try:
    print(5 / 0)
except ZeroDivisionError:
    print("分母不能为0")

try:
    print(5 / 0)
except Exception as my_except: # 总体异常处理
    print(f"发生错误---{my_except}")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
11、异常的妥善处理
print("Give me two numbers, and I'll divide them.")
print("Enter 'q' to quit.")
while True:
    first_number = input("\nFirst number: ")
    if first_number == 'q':
        break
    second_number = input("Second number: ")
    try:
        answer = int(first_number) / int(second_number)
    except ZeroDivisionError:
        print("You can't divide by 0!")
    else:
        print(answer)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
12、文件找不到错误
filename = 'alice.txt'
try:
    with open(filename) as f_obj:
        contents = f_obj.read()
except Exception as my_except:
    print(f"发生错误---{my_except}")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
13、pass的用法
在前一个示例中,我们告诉用户有一个文件找不到。但并非每次捕获到异常时都需要告诉用户,有时候你希望程序在发生异常时一声不吭,就像什么都没有发生一样继续运行。 要让程序在失败时一声不吭,可像通常那样编写try 代码块,但在except 代码块中明确地告诉Python什么都不要做。Python有一个pass 语句,可在代码块中使用它来让Python 什么都不要做。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
14、存储数据
很多程序都要求用户输入某种信息,如让用户存储游戏首选项或提供要可视化的数据。不管专注的是什么,程序都把用户提供的信息存储在列表和字典等数据结构中。用户关闭程序时,你几乎总是要保存他们提供的信息;一种简单的方式是使用模块json 来存储数据。
import json

numbers = [2, 3, 5, 7, 11, 13]
filename = 'out.txt'  # 把数据写入到out.txt里面去
with open(filename, 'w') as f_obj:
    json.dump(numbers, f_obj)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
15、数据存储与读取,感觉挺先进的,用JSON作为中介质
import json

numbers = {
    "level": 1
}
filename = 'out.txt'
with open(filename, 'w') as f_obj:
    json.dump(numbers, f_obj)

with open(filename) as f_obj:
    numbers = json.load(f_obj)
    print(numbers)

注意:
json.dumps():将Python对象转换为JSON格式的字符串。
json.dump():将Python对象直接写入文件,并将其转换为JSON格式

json.loads():从字符串中读取JSON数据并解析为Python对象
json.load():从文件对象中读取JSON数据并解析为Python对象。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
16、保存和和读取用户生成的的数据
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
17、重构
代码能够正确地运行,但可做进一步的改进——将代码划分为一系列完成具体工作的函数。这样的过程被称为重构。重构让代码更清晰、更易于理解、更容易扩展。
要编写出清晰而易于维护和扩展的代码,这种划分工作必不可少。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
*******************************************************************************************************************************************
第十一章:测试代码
*******************************************************************************************************************************************
1、测试函数
def get_formatted_name(first, last):
    """Generate a neatly formatted full name."""
    full_name = first + ' ' + last
    return full_name.title()


print("Enter 'q' at any time to quit.")
while True:
    first = input("\nPlease give me a first name: ")
    if first == 'q':
        break
    last = input("Please give me a last name: ")
    if last == 'q':
        break
    formatted_name = get_formatted_name(first, last)
    print("\tNeatly formatted name: " + formatted_name + '.')
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
项目部分===》
*******************************************************************************************************************************************
第十二章:外星人入侵
*******************************************************************************************************************************************
1、安装Pygame
接下来的部分包含在各种系统上安装pip的说明,因为数据可视化项目和Web应用程序项目都需要pip。
pip --version
请尝试将pip替换为pip3。如果这两个版本都没有安装到你的系统中,请跳到“安装pip”。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
2、配置从阿里云下载pip
python get-pip.py
C:\Users\HIT\AppData\Roaming\pip #打开此位置,根据自己的用户名找\AppData\Roaming
新建\pin\pip.ini
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
pip install --upgrade pip #升级pip,如果报错Consider using the `--user` option or check the permissions.请注意更改python的权限,打开python所在位置,把完全控制都打上勾然后再执行
pip install pandas #可以看到从阿里云下载包
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
3、PYTHON大写,PYTHON代码从无大写
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
4、设置类和显示UI
class Settings():  # 设置类
    def __init__(self):
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (230, 230, 230)

# coding:utf8
import sys

import pygame
import settings


def run_game():
    pygame.init()  # 初始化游戏创建一个屏幕对象
    settings_entity = settings.Settings()
    screen = pygame.display.set_mode((settings_entity.screen_width, settings_entity.screen_height))
    pygame.display.set_caption('alien game')
    while True:  # 开始游戏的主循环
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        screen.fill(settings_entity.bg_color)  # 设置背景色
        pygame.display.flip()  # 让最近绘制的屏幕可见


run_game()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
5、添加飞船图像
http://pixabay.com/  图像来源
创建ship类
import pygame


class Ship():
    def __init__(self, screen):
        self.screen = screen
        self.image = pygame.image.load('img/ship.png')
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()

        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom

    def blit_me(self):
        self.screen.blit(self.image, self.rect)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
6、优化代码
game_functions
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
7、让飞船移动
*******************************************************************************************************************************************
第十三章:数据可视化
*******************************************************************************************************************************************
1、绘制折线图
import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
*******************************************************************************************************************************************
第十四章:下载数据
*******************************************************************************************************************************************
*******************************************************************************************************************************************
第十五章:使用API
*******************************************************************************************************************************************
1、import requests

# 执行API调用并存储响应
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
print("Status code:", r.status_code)
# 将API响应存储在一个变量中
response_dict = r.json()
# 处理结果
print(response_dict)
print(response_dict.keys())
2、字典解析
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
import requests

# 执行API调用并存储响应
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
print("Status code:", r.status_code)
# 将API响应存储在一个变量中
response_dict = r.json()
print("Total repositories:", response_dict['total_count'])
# 探索有关仓库的信息

repo_dicts = response_dict['items']
print("Repositories returned:", len(repo_dicts))
# 研究第一个仓库

repo_dict = repo_dicts[0]
print("\nKeys:", len(repo_dict))
for key in sorted(repo_dict.keys()):
    print(key)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
3、可视化仓库
import pygal
import requests
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS

# 执行API调用并存储响应
URL = 'https://api.github.com/search/repositories?q=language:python&sort=star'
r = requests.get(URL)
print("Status code:", r.status_code)
# 将API响应存储在一个变量中
response_dict = r.json()
print("Total repositories:", response_dict['total_count'])
# 研究有关仓库的信息
repo_dicts = response_dict['items']
names, stars = [], []
for repo_dict in repo_dicts:
    names.append(repo_dict['name'])
stars.append(repo_dict['stargazers_count'])
# 可视化
my_style = LS('#333366', base_style=LCS)
chart = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=False)
chart.title = 'Most-Starred Python Projects on GitHub'
chart.x_labels = names
chart.add('', stars)
chart.render_to_file('python_repos.svg')
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
*******************************************************************************************************************************************
第十六章:Web应用程序
*******************************************************************************************************************************************
1、如果你使用的是Windows系统,请使用命令ll_env\Scripts\activate (不包含source )来激活这个虚拟环境。 要停止使用虚拟环境,可执行命令deactivate 。
 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com