GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - JasonDong97/learn-python: 📚 Python 学习笔记。Python脚本的集合,按目录划分,并包含带解释的代码示例

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

46 Commits
46 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
src
src
 
 
.flake8
.flake8
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
LICENSE
LICENSE
 
 
README.en.md
README.en.md
 
 
README.md
README.md
 
 
README.pt-BR.md
README.pt-BR.md
 
 
_config.yml
_config.yml
 
 
pylintrc
pylintrc
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

Python 学习笔记

Build Status

这是 Python 脚本的集合,按 目录划分,包含带有解释的代码示例、不同的用例和进一步阅读的链接。

这是一个练习场,因为您可以更改或添加代码以查看它是如何工作的, 并使用断言 测试代码。它还允许您 代码检测 并检查它是否符合 Python 代码风格指南。 总而言之,它可能会使您的学习过程更具交互性,并且可能会帮助您从一开始就保持较高的代码质量。

这是一个备忘单,因为一旦您想回顾标准 Python 语句和结构的语法,您可能会回到这些代码示例。 此外,由于代码中充满了断言,您无需启动它们就可以立即看到预期的函数语句输出。

你可能也对🤖感兴趣 交互式机器学习实验

如何使用此存储库

此存储库中的每个 Python 脚本都具有以下结构:

"""Lists  <--- 这里的主题名称

# @see: https://www.learnpython.org/en/Lists  <-- 进一步阅读的链接在这里

这里可能会对当前主题进行更详细的解释(即关于列表的一般信息)。
"""


def test_list_type():
    """
        子主题的解释在这里。每个文件都包含说明子主题的测试函数(即列表类型、列表方法)。
    """
    
    # 以下是如何构建列表的示例。 <-- 这里的评论解释了这个动作
    squares = [1, 4, 9, 16, 25]
    
    # 列表可以被索引和切片。
    # 索引返回项目。
    assert squares[0] == 1  # <-- 这里的断言说明了结果。
    # 切片返回一个新列表。
    assert squares[-3:] == [9, 16, 25]  # <-- 这里的断言说明了结果。

所以通常你可能想要执行以下操作:

  • Find the topic你想学习或回顾。
  • 阅读每个脚本的文档字符串中链接的注释和/或文档(如上例所示)。
  • 查看代码示例和断言以查看使用示例和预期输出。
  • 更改代码或添加新断言以查看工作方式。
  • Run tests and lint the code 看看它是否有效并且是否正确写入。

目录

  1. 入门
    • 什么是 Python
    • Python 语法
    • 变量
  2. 运算符
    • 算术运算符 (+, -, *, /, //, %, **)
    • 位运算符 (&, |, ^, >>, <<, ~)
    • 赋值运算符 (=, +=, -=, /=, //= etc.)
    • 比较运算符 (==, !=, >, <, >=, <=)
    • 逻辑运算符 (and, or, not)
    • 恒等运算符 (is, is not)
    • 成员运算符 (in, not in)
  3. 数据类型
    • 数字 (其中包括布尔值)
    • 字符串 以及方法
    • 列表 以及方法(包括列表推导式)
    • 元组
    • 集合及其方法
    • 字典
    • 类型转换
  4. 控制
    • if
    • for (以及 range() 函数)
    • while
    • try
    • break
    • continue
  5. 函数
    • 函数定义 (def and return statements)
    • 函数内部变量的作用域 (global and nonlocal statements)
    • 默认参数值
    • 关键字参数
    • 任意的参数列表
    • 拆包参数列表 (* and ** statements)
    • Lambda表达式 (lambda statement)
    • 文档字符串
    • 函数注释
    • 函数修饰符
  6. 类
    • 类定义 (class statement)
    • 类对象
    • 实例对象
    • 方法对象
    • 类和实例变量
    • 继承
    • 多重继承
  7. 组件
    • 模块 (import statement)
    • 包
  8. 错误和异常
    • 处理异常 (try statement)
    • 提高异常 (raise statement)
  9. 文件
    • 读与写 (with statement)
    • 文件对象的方法
  10. 附加物
    • pass 声明
    • 生成器 (yield 声明)
  11. 标准库简介
    • 序列化 (json library)
    • 文件通配符 (glob library)
    • 字符串匹配 (re library)
    • 数学运算 (math, random, statistics libraries)
    • 日期和时间 (datetime library)
    • 数据压缩 (zlib library)

预备知识

安装Python

确保你安装了Python3 on your machine.

你可能想要使用venv标准Python库 创建虚拟环境并安装Python、pip和所有依赖包从本地项目目录提供,以避免与系统范围的包及其版本。

根据你的安装,你可以通过运行python 或 python3。pip包管理器也是如此——它也可能是可访问的 通过运行 pip 或pip3。

You may check your Python version by running:

python --version

Note that in this repository whenever you see python it will be assumed that it is Python 3.

Installing dependencies

Install all dependencies that are required for the project by running:

pip install -r requirements.txt

测试代码

测试使用 pytest 框架.

您可以通过 test_ 作为前缀添加文件和函数为自己添加新的测试 (例如: 在 test_topic.py 里添加 def test_sub_topic() 函数).

要运行所有测试,请从项目根文件夹执行以下命令:

pytest

要运行特定的测试,请执行:

pytest ./path/to/the/test_file.py

代码检测

代码检测用的是 pylint 和 flake8 库.

PyLint

来检查代码是否按 PEP 8 规定编写,请执行:

pylint ./src/

以防linter检测到错误 (i.e. missing-docstring) 你可能想读更多关于 具体运行错误:

pylint --help-msg=missing-docstring

More about PyLint

Flake8

来检查代码是否按 PEP 8 规定编写,请执行:

flake8 ./src

或者,如果你想有更详细的输出,你可以运行:

flake8 ./src --statistics --show-source --count

About

📚 Python 学习笔记。Python脚本的集合,按目录划分,并包含带解释的代码示例

Resources

Readme
MIT license

Code of conduct

Code of conduct
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.