别院牧志知识库 别院牧志知识库
首页
  • 基础

    • 全栈之路
    • 😎Awesome资源
  • 进阶

    • Python 工匠系列
    • 高阶知识点
  • 指南教程

    • Socket 编程
    • 异步编程
    • PEP 系列
  • 面试

    • Python 面试题
    • 2025 面试记录
    • 2022 面试记录
    • 2021 面试记录
    • 2020 面试记录
    • 2019 面试记录
    • 数据库索引原理
  • 基金

    • 基金知识
    • 基金经理
  • 细读经典

    • 德隆-三个知道
    • 孔曼子-摊大饼理论
    • 配置者说-躺赢之路
    • 资水-建立自己的投资体系
    • 反脆弱
  • Git 参考手册
  • 提问的智慧
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
首页
  • 基础

    • 全栈之路
    • 😎Awesome资源
  • 进阶

    • Python 工匠系列
    • 高阶知识点
  • 指南教程

    • Socket 编程
    • 异步编程
    • PEP 系列
  • 面试

    • Python 面试题
    • 2025 面试记录
    • 2022 面试记录
    • 2021 面试记录
    • 2020 面试记录
    • 2019 面试记录
    • 数据库索引原理
  • 基金

    • 基金知识
    • 基金经理
  • 细读经典

    • 德隆-三个知道
    • 孔曼子-摊大饼理论
    • 配置者说-躺赢之路
    • 资水-建立自己的投资体系
    • 反脆弱
  • Git 参考手册
  • 提问的智慧
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 辨析

  • Sockets编程

  • Django

  • stackoverflow

    • StackOverflow Python 相关问题精选
      • 基础语法
        • Python 是否有三元运算符
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
      • 基本数据结构
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
      • 进阶函数和类
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
      • 系统
        • 🔗
        • 🔗
      • 数据库
        • 🔗
      • 其他
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
        • 🔗
      • 来源
      • stackoverflow-py-top-qa
      • PyZh
      • StackOverFlowCn
      • stackoverflow_python
    • StackOverflow Python 问题 Top-100
  • Flask

  • 全栈之路

  • 面试

  • 代码片段

  • 异步编程

  • 😎Awesome资源

  • PEP

  • Python工匠系列

  • 高阶知识点

  • Python 学习资源待整理
  • 设计模式

  • 好“艹蛋”的 Python 呀!
  • FIFO | 待学清单📝
  • pip 安装及使用
  • 数据分析

  • 源码阅读计划

  • OOP

  • 关于 python 中的 setup.py
  • 并行分布式框架 Celery
  • 七种武器,让你的代码提高可维护性
  • 使用 pdb 调试 Python 代码
  • 每周一个 Python 标准库
  • 🐍Python
  • stackoverflow
佚名
2020-05-23
目录

StackOverflow Python 相关问题精选

# 基础语法

  • 基本语法控制流相关 (opens new window)

  • 字符串相关 (opens new window)

  • 文件相关 (opens new window)

  • 数学相关 (opens new window)

  • # Python 是否有三元运算符 (opens new window)

    • Python 是否有三元运算符 (opens new window)
  • # 🔗 (opens new window)

    • Python 中用什么代替 switch 语句? (opens new window)
  • # 🔗 (opens new window)

    • 在 Python 里如何读取 stdin? (opens new window)
  • # 🔗 (opens new window)

    • 输出到 stderr (opens new window)

# str

  • # 🔗 (opens new window)

    • 检查字符串为空的最优雅的方法 (opens new window)
  • # 🔗 (opens new window)

    • 检查一个字符串是否是一个数字 (opens new window)
  • # 🔗 (opens new window)

    • 把字符串解析成浮点数或者整数 (opens new window)
  • # 🔗 (opens new window)

    • 整数转化为字符串 (opens new window)
  • # 🔗 (opens new window)

    • bytes 换成 string (opens new window)
  • # 🔗 (opens new window)

    • 反转字符串 (opens new window)
  • # 🔗 (opens new window)

    • 字符串格式化:%和.format (opens new window)
  • # 🔗 (opens new window)

    • 如何在 .format 中使用大括号? (opens new window)
  • # 🔗 (opens new window)

    • 限制浮点型到小数点后两位 (opens new window)
  • # 🔗 (opens new window)

    • 给字符串填充 0 (opens new window)
  • # 🔗 (opens new window)

    • 生成包含大写字母和数字的随机字符串 (opens new window)
  • 如何在 Python 中检查一个字符串否可转化为数字? (opens new window)
  • # 🔗 (opens new window)

    • 把字符串转化成时间 (opens new window)
  • # 🔗 (opens new window)

    • 在 Python 中如何将字符串转化为小写 (opens new window)
  • # 🔗 (opens new window)

    • 如何移除换行符? (opens new window)
    • 如何删除 Python 中的换行符? (opens new window)
  • # 🔗 (opens new window)

    • 判断一个字符串是否含子串的方法 (opens new window)
    • Python 中有检查字符串包含的方法吗? (opens new window)

# list

  • # 🔗 (opens new window)

    • Python 中的 appen 和 extend (opens new window)
    • append 和 extend 的区别 (opens new window)
  • # 🔗 (opens new window)

    • 获得 Python 的循环索引 (opens new window)
    • 在循环中获取索引(数组下标) (opens new window)
  • # 🔗 (opens new window)

    def foo(a=[]):        
        a.append(5)
        return a
    # out
    >>> foo()
    [5]
    >>> foo()
    [5, 5]
    >>> foo()
    [5, 5, 5]
    >>> foo()
    [5, 5, 5, 5]
    >>> foo()
    # 改写
    
    def foo(a=None):
        if a is None:
            a = list()        
        a.append(5)
        return a
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    • Python 中的"小震撼":变化的默认参数 (opens new window)
  • # 🔗 (opens new window)

    l = [[1, 2, 3], [4, 5, 6], [7], [8, 9]]
    flat_list = [item for sublist in l for item in sublist]
    print(flat_list)
    
    1
    2
    3
    • 在嵌套列表中获取 flat list|即:列表展开 (opens new window)
  • # 🔗 (opens new window)

    • 怎么样获取一个列表的长度? (opens new window)
  • # 🔗 (opens new window)

    tuple(l[i:i+n] for i in xrange(0, len(l), n))
    
    1
    • 在 Python 怎么样才能把列表分割成同样大小的块? (opens new window)
  • # 🔗 (opens new window)

    • 如何克隆或者 copy 一个 list ? (opens new window)
  • # 🔗 (opens new window)

    • 获取列表最后一个元素 (opens new window)
  • # 🔗 (opens new window)

    • 如何删除 list 中指定 index 的元素? (opens new window)
  • # 🔗 (opens new window)

    • 合并两个列表 (opens new window)
  • # 🔗 (opens new window)

    • 使用列表推导式的方式来创建字典 (opens new window)
  • # 🔗 (opens new window)

    • 如何使打印的内容没有空格或换行 (opens new window)
  • # 🔗 (opens new window)

    • 检查列表是否为空的最好方法 (opens new window)
  • # 🔗 (opens new window)

    • 查找列表中某个元素的下标 (opens new window)
  • 如何将 Python 列表均匀划分? (opens new window)
  • join 函数为什么是 string.join(list)而不是 list.join(string) (opens new window)

# dict

  • # 🔗 (opens new window)

    • 检查一个键在字典中是否存在 (opens new window)
    • 查看某个给定的键是否已经在字典中 (opens new window)
  • # 🔗 (opens new window)

    • 字典里添加元素的方法 (opens new window)
  • # 🔗 (opens new window)

    • 如何把两个 Python 字典用一个表达式合并 (opens new window)
    • 如何在一个表达式里合并两个字典? (opens new window)
  • # 🔗 (opens new window)

    • 用字典的值(key)对字典进行排序 (opens new window)
    • 对 Python 字典按值排序 (opens new window)
  • # 🔗 (opens new window)

    • 在 Python 中如何移除字典中的 key ? (opens new window)
  • # 🔗 (opens new window)

    • 使用 for 来迭代字典的原理 (opens new window)
  • # 🔗 (opens new window)

    • __str__和repr__的区别 (opens new window)
    • Python 中的 __str__和__repr__之间的区别 (opens new window)
  • # 🔗 (opens new window)

    • 在 Python 里如何用枚举类型? (opens new window)
    • 怎样在 Python 中实现 Enum(枚举)的功能 (opens new window)
  • # 🔗 (opens new window)

    • 手动抛出异常 (opens new window)
  • # 🔗 (opens new window)

    • 在一行里获取多个异常 (opens new window)
    • 将多行的异常变成一行 (opens new window)
  • # 🔗 (opens new window)

    • 理解 Python 切片 (opens new window)
    • 解释 Python 的切片法 (opens new window)
  • # 🔗 (opens new window)

    • 获得一个字符串的子串|切片操作(slice) (opens new window)

# 时间

  • # 🔗 (opens new window)

    • 在 Python 里获取当前时间 (opens new window)
    • 如何在 Python 中获取当前时间 (opens new window)

# 文件

  • # 🔗 (opens new window)

    • 如何使用 Python 来检查文件是否存在 (opens new window)
    • 用 Python 如何判断一个文件是否存在? (opens new window)
  • # 🔗 (opens new window)

    • 检查一个文件夹是否存在,如果不存在就创建它 (opens new window)
    • 检查目录是否存在,如果有必要就创建一个目录 (opens new window)
  • # 🔗 (opens new window)

    • 复制文件 (opens new window)
  • # 🔗 (opens new window)

    • 删除文件或者文件夹 (opens new window)
  • # 🔗 (opens new window)

    • 如何在 Python 中列出目录下的所有文件 (opens new window)
    • 在 Python 中列出目录中的所有文件 (opens new window)
  • # 🔗 (opens new window)

    • 查找当前目录和文件目录 (opens new window)
  • # 🔗 (opens new window)

    • 找出文件夹中所有扩展名为 .txt 的文件 (opens new window)
  • # 🔗 (opens new window)

    • 把文件一行行读入数组 (opens new window)
  • # 🔗 (opens new window)

    • 如何增加文件的内容? (opens new window)
  • # 🔗 (opens new window)

    • 如何解析一个 JSON 文件? (opens new window)

#

  • # 🔗 (opens new window)

    • 如何在一个函数里用全局变量? (opens new window)
  • # 🔗 (opens new window)

    • 怎么用引用来改变一个变量? (opens new window)
    • 如何通过参数来传递一个变量? (opens new window)
  • # 🔗 (opens new window)

    • 在 Python 中如何得到对象的所有属性? (opens new window)
  • # 🔗 (opens new window)

    • Python 中**和*参数有什么用? (opens new window)
  • # 🔗 (opens new window)

    • *args和 **kwargs (opens new window)
  • # 🔗 (opens new window)

    • 通过函数名的字符串来调用这个函数 (opens new window)

# 基本数据结构

  • 列表 (opens new window)

  • 元组 (opens new window)

  • 字典 (opens new window)

  • # 🔗 (opens new window)

    list_to_be_sorted = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]   # >>> [{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}]
    newlist = sorted(list_to_be_sorted, key=lambda k: k['name'])
    # 或者用标准库中的方法:
    from operator import itemgetter
    newlist = sorted(list_to_be_sorted, key=itemgetter('name'))
    
    
    1
    2
    3
    4
    5
    6
    • 通过列表中字典的值对列表进行排序 (opens new window)
  • # 🔗 (opens new window)

    • 在列表中随机取一个元素 (opens new window)
  • # 🔗 (opens new window)

    • 如何计算列表中元素出现的个数? (opens new window)
  • # 🔗 (opens new window)

    • 为什么 "1000000000000000 in range(1000000000000001)" 在 Python3 里速度那么快? (opens new window)
  • # 🔗 (opens new window)

    • 为什么是 string.join(list)而不是 list.join(string)? (opens new window)

# 进阶函数和类

  • 函数 (opens new window)

  • 内置函数 (opens new window)

  • 异常 (opens new window)

  • 模块 (opens new window)

  • 标准库 (opens new window)

  • 日期 (opens new window)

  • oop (opens new window)

  • # 🔗 (opens new window)

    • 查看一个对象的类型 (opens new window)
  • # 🔗 (opens new window)

    • type()和isinstance()的区别 (opens new window)
  • # 🔗 (opens new window)

    • 如何查看 Python 变量的类型? (opens new window)
  • # 🔗 (opens new window)

    • 如何获取实例的类名 (opens new window)
  • # 🔗 (opens new window)

    • Python 中 yield 关键词的作用是什么 (opens new window)
    • Python 关键字yield的解释 (opens new window)
    • Python 中关键字 yield 有什么作用? (opens new window)
  • # 🔗 (opens new window)

    • Python 中的元类是什么 (opens new window)
    • Python 中的元类(metaclass)是什么? (opens new window)
    • Python 元类 (opens new window)
  • # 🔗 (opens new window)

    • Python 中如何在一个函数中加入多个装饰器? (opens new window)
    • 怎样在 Python 中创建函数装饰器链 (opens new window)
  • # 🔗 (opens new window)

    • if __name__ == "__main__"是做什么用的 (opens new window)
    • if __name__ == "__main__":有什么作用? (opens new window)
  • # 🔗 (opens new window)

    • @staticmethod(静态方法)和@classmethod(类方法)的区别 (opens new window)
    • 装饰器@staticmethod 和@classmethod 有什么区别? (opens new window)
  • # 🔗 (opens new window)

    • 在实例名字前单下划线和双下划线的含义 (opens new window)
  • # 🔗 (opens new window)

    • 对于初学者如何理解 @classmethod 和 @staticmethod? (opens new window)
  • # 🔗 (opens new window)

    • Python 中类的静态变量 (opens new window)
  • # 🔗 (opens new window)

    • 静态方法 (opens new window)
    • Python 中的静态方法? (opens new window)
  • # 🔗 (opens new window)

    • 理解 Python 中super()和__init__()方法 (opens new window)
  • 如何使用 ' super ' (opens new window)
  • # 🔗 (opens new window)

    • __init__.py 的作用 (opens new window)
  • Python 中的新式类和旧式类 (opens new window)

# 系统

  • # 🔗 (opens new window)

    • 在 Python 中调用外部命令 (opens new window)
    • 在 Python 中调用外部命令 (opens new window)
  • # 🔗 (opens new window)

    • 如何使用线程 (opens new window)

# 数据库

  • # 🔗 (opens new window)

    • 如何连接 MySQL? (opens new window)

# 其他

  • # 🔗 (opens new window)

    • 怎么在 windows 下安装 pip? (opens new window)
  • # 🔗 (opens new window)

    • 在 macOS 上如何安装 pip (opens new window)
  • # 🔗 (opens new window)

    • 用 pip 升级所有包 (opens new window)
  • pip/easy_install (opens new window)

  • setup.py s requirements.txt (opens new window)

  • # 🔗 (opens new window)

    • 在 Python 中如何获取环境变量 (opens new window)
  • # 🔗 (opens new window)

    • 如何测量脚本运行时间? (opens new window)
  • # 🔗 (opens new window)

    • UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128) (opens new window)
  • # 🔗 (opens new window)

    • 有方法让 Python 运行在 Android 上吗? (opens new window)
  • # 🔗 (opens new window)

    • 如何离开/退出/停用 Python 的 virtualenv? (opens new window)
  • # 🔗 (opens new window)

    • 怎么在终端里输出颜色? (opens new window)
  • 其他 (opens new window)


  • # 🔗 (opens new window)

    • Python 的一些语言特性|此文未翻译,建议直接阅读链接 (opens new window)
  • 为什么 Python 没有 unzip 函数 (opens new window)

  • (译)Python 魔法方法指南 (opens new window)

# 来源

Fork from:

# stackoverflow-py-top-qa (opens new window)

# PyZh (opens new window)

# StackOverFlowCn (opens new window)

# stackoverflow_python (opens new window)

编辑 (opens new window)
#Python#StackOverflow
上次更新: 2024-07-23, 01:00:43
教程 6:ViewSets 和 Routers
StackOverflow Python 问题 Top-100

← 教程 6:ViewSets 和 Routers StackOverflow Python 问题 Top-100→

最近更新
01
2025 面试记录
05-28
02
提升沟通亲和力的实用策略
03-26
03
工作
07-15
更多文章>
Theme by Vdoing | Copyright © 2019-2025 IMOYAO | 别院牧志
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式