python代码规范化工具

目录

1.安装autopep8工具可以将代码规范化

指令

autopep8 --in-place --aggressive --aggressive demo.py
2. 共享文件

在某一文件下执行

python -m http.server

在浏览器中输入'xxx.xxx.xxx.xxx.8000' 即可查看、下载该文件夹下文件

3. 字典排序(根据key或者value)
4. 通过dict实现switch语句
def calc(operator, x, y):
    operator_dict = {
        '+': x + y,
        '-': x - y,
        '*': x * y,
        '/': x / y,
    }

    result = operator_dict.get(operator, None)
    if result is None:
        return 'invalid operator'
    else:
        return result

print (calc('+', 2, 1))

猜你喜欢

转载自www.cnblogs.com/yeran/p/11751015.html
今日推荐