# TheAlgorithms-Python-Chinese **Repository Path**: chiation/TheAlgorithms-Python-Chinese ## Basic Information - **Project Name**: TheAlgorithms-Python-Chinese - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-05-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 算法 - Python [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Python) [![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms)  [![Build Status](https://img.shields.io/travis/TheAlgorithms/Python.svg?label=Travis%20CI&logo=travis&style=flat-square)](https://travis-ci.com/TheAlgorithms/Python)  [![LGTM](https://img.shields.io/lgtm/alerts/github/TheAlgorithms/Python.svg?label=LGTM&logo=LGTM&style=flat-square)](https://lgtm.com/projects/g/TheAlgorithms/Python/alerts)  [![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square)](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)  [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg?logo=paypal&style=flat-square)](https://www.paypal.me/TheAlgorithms/100)  ![](https://img.shields.io/github/repo-size/TheAlgorithms/Python.svg?label=Repo%20size&style=flat-square)  ## 引言 欢迎 !有任何问题请看原github——[TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! ### 所有的算法都是已学习为目的,可能不如一些python库 These implementations are for learning purposes. They may be less efficient than the implementations in the Python standard library. ### 为了方便学习,将github上转移到gitee,且转为中文,以下为原网址 [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python) ## 贡献准则 #### 算法简介 算法是一个或多个函数(或类),应该具有以下特性: - 接受一个或多个输入, - 执行一些内部计算或数据处理, - 返回一个或多个输出, - 具有最小的副作用(例如print(),plot(),read(),write())。 - 易于与读者将其放入较大的程序中 算法应当: - 具有直观的类和函数名称,使读者可以清楚地了解其用途 - 使用Python命名约定和直观的变量名称来简化理解 - 灵活地采用不同的输入值 - 输入内容和返回值具有Python类型提示 - 对错误的输入值引发Python异常(ValueError等) - 具有明确说明和原始资料网址的文档字符串 - 包含可同时测试有效和错误输入值的doctest - 返回所有计算结果,而不是打印或绘制它们 #### 代码风格 为了方便阅读,此仓库的代码应具有以下风格的约束: - Please write in Python 3.7+. - 请重点关注函数,类和变量的命名,使用描述性命名方式以减少备注和方便阅读. - 如果不是只有几行的调用,请不要使用单变量命名. - 遵守Python命名方式. - 函数变量名小写,类名使用驼峰原则. - 格式化代码为PEP 8,可以使用block和flake8来格式化代码 - 请适当添加注释,请看下例: ```python x = x + 2 # increased by 2 ``` 以上代码如果过多会影响阅读,过于繁琐,不如下边这种写法 - 注释有解释作用 - 对于同一段代码,如果有一致性可以把放在代码段的上或下 - 建议放在函数里 ```python def sum_ab(a, b): """ Return the sum of two integers a and b. """ return a + b ``` - 写测试段 (尤其是用[__doctests__](https://docs.python.org/3/library/doctest.html) 来讲解).我们建议在所有的代码段上使用[__doctests__](https://docs.python.org/3/library/doctest.html) 。 ```python def sum_ab(a, b): """ Return the sum of two integers a and b >>> sum_ab(2, 2) 4 >>> sum_ab(-2, 3) 1 >>> sum_ab(4.9, 5.1) 10.0 """ return a + b ``` - 不建议使用 __input()__ ```python input('Enter your input:') # Or even worse... input = eval(input("Enter your input: ")) ``` + 可以这样使用 ```python starting_value = int(input("Please enter a starting value: ").strip()) ``` - 参数和返回值 ```python def sum_ab(a: int, b: int) -> int: return a + b ``` - 列表生成式尽量优先于 `lambda`, `map`, `filter`, `reduce` - 不建议引入其他三方库 #### 其他 - 不建议创建新的目录,除非必须 - 不要更新readme.md。