排序
Day 8 – 函数参数
有参函数 带有输入参数的函数即为有参函数,有参函数的基本语法 # 函数定义 def <function name>(param1, param2,...): # Do this with param1, param2,... # 函数调用 <function name>(a...
Day 5 – 循环
for 循环 for 循环的基本语法,如下所示 for item in list_of_items: # do something to each item 示例代码 fruits = ['Apple', 'Peach', 'Pear'] for fruit in fruits: print(fruit) # Apple ...
Day 10 – 函数输出
单返回值 函数通过 return 关键字,进行函数的输出。 def function_name(input_parameter): <body of function that uses input_argument> return output 示例代码 def format_name(f_nam...
Day 4 – 随机化与列表
随机化 Python 提供random模块以实现随机化。详情可参考 https://docs.python.org/zh-cn/3.13/library/random.html # 导入 random 模块 import random # 1 到 10 的随机整数 rand_num = random....
Day 6 – 函数
Python 内置函数的详情可参考 https://docs.python.org/zh-cn/3.13/library/functions.html 函数定义 无参函数的语法 # 函数定义 def <function name>(): # Do something # 函数调用 <...
Day 1 – Python 变量与数据管理
打印 Python 中的打印语句 print('Hello world!') 字符串操作 字符串连接 字符串的连接可以使用+操作符 print('Hello' + ' ' + 'world!') 字符串长度 字符串的长度计算,使用len()函数 输入函数...
Day 2 – 理解数据类型和字符串操作
基本数据类型 String 字符串下标 字符串的下标 Subscripting可以提取字符串特定位置的字符。 # 提取第一个字符 print('Hello'[0]) # H # 提取最后一个字符 print('Hello'[len('Hello') - 1]) # ...
Day 21 – 贪吃蛇(下)
类继承 从现有类继承行为和外观的过程成为类继承。这里的行为和外观分别为类的方法和属性。类继承可以对现有的类进行属性以及方法的扩展。 # Fish类 class Fish: def __init__(self): '''初始化...
macOS Python 多版本管理
安装 Homebrew Homebrew 的官网 https://brew.sh/ 在终端输入以下命令进行安装 /bin/bash -c '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)' 安装完成后...
Day 9 – 字典与嵌套
字典 基本语法 字典是由键值对组成,基本的语法如下 {key1:value1, key2: value2, ...} 示例 # 字典示例 colors = { 'apple': 'red', 'pear': 'green', 'banana': 'yellow' } 基本使用 字典的基...



