Python相关文章索引(4)

基本常识

  1. python的类中def init是什么意思,做什么用的,有什么要求吗?

用途:
初始化实例的值.这些值一般要供其他方法调用
要求:
只初始化值,不要返回值(就是别用return)

  1. Pyhton 单行、多行注释符号使用方法及规范

单行注释:#
多行注释: ”’ ”’

  1. Python基础-作用域和命名空间(Scope and Namespace)

  2. python 中文中有数字 如何输出

  3. Python pass 语句

Python pass是空语句,是为了保持程序结构的完整性。
pass 不做任何事情,一般用做占位语句。

  1. python 如何调用类的方法

  2. python语句:for _ in range(5)是什么意思,“_”是什么用法?

  3. python 1 and 2 怎么就返回2了

  4. python算法入门 — 栈(stack)

  5. Python 运算符

  6. python lambda

金手指

函数

  1. sqrt()
    Python sqrt() 函数
    Python 平方根

sqrt() 方法返回数字x的平方根。

  1. abs()
    python函数每日一讲 – abs()

返回绝对值

  1. max()
    python中怎么利用max函数处理list?
    Python List max()方法

  2. len()
    python 获取字符串长度

  3. split()
    Python split()方法

Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串

  1. cmp()
    Python cmp() 函数

cmp(x,y) 函数用于比较2个对象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1。

  1. insert()
    Python List insert()方法

insert() 函数用于将指定对象插入列表的指定位置。

  1. upper()&lower()
    Python 字符串大小写转换

upper()将字符串转换为大写字母
lower()将字符串转为小写字母

  1. reduce()
    python的reduce()函数

reduce()对list的每个元素反复调用函数f,并返回最终结果值。

  1. enumerate()
    python中的enumerate函数

enumerate 函数用于遍历序列中的元素以及它们的下标

  1. range()
    详细记录python的range()函数用法

  2. flatten()
    Python中flatten用法

  3. sum()
    python 中求和函数 sum详解

sum()的参数是一个list

  1. isupper()
    Python中用于检查英文字母大写的isupper()方法

isupper()方法检查字符串的所有基于大小写的字符(字母)是否是大写。

  1. ord()&chr()
    python中怎么将一个字符变成ascll值

ord():字符变ASCII
chr(): ASCII变字符

模块

  1. operator模块
    python operator — 标准函数操作

  2. Collections模块
    [Python标准库——collections模块的Counter类]
    (http://www.pythoner.com/205.html)

  3. copy模块
    Python中使用copy模块实现列表(list)拷贝

如果你想实现深拷贝,不妨使用copy.deepcopy()

数据操作

排序

  1. python中的sort方法使用详解

  2. Python 列表sort()添加key和reverse参数操作方法

  3. python sort、sorted高级排序技巧

//履用不爽,必要时还可以加上reverse=True来进一步实现自己所需要的排序
>>> student_tuples = [
        ('john', 'A', 15),
        ('jane', 'B', 12),
        ('dave', 'B', 10),
]
>>> sorted(student_tuples, key=lambda student: student[2])   # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

python中字典按键或键值排序

sorted(dict.items(), key=lambda e:e[1], reverse=True)
  1. python字符串排序方法

List

  1. Python_Python遍历列表的四种方法
/*个人比较喜欢使用如下两种方式来遍历列表*/
list=[1,2,3,4,5]
//类似Java增强for循环:
for i in list:
          print i
//朴素遍历,可以获取到元素索引:
for i in range(len(list)):
          print list[i]
  1. python中list操作详解

  2. python实现list数组转置

  3. 如何在python中倒序遍历数组

  4. python 两个list 求交集,并集,差集

String

  1. Python字符串处理NoneType的处理

  2. python字符串字串查找 find和index方法

  3. Python字符串反转

s = ‘abcde’
s[::-1]

  1. python判断字符串是否包含子字符串的方法

直接用in 和 not in,和to be 和 not to be道理是一样的

  1. Python进阶—python实现substring截取子字符串

  2. python 生成长度为100的字符串,值全为1

(‘1’*100)

  1. python如何比较两个字符串

直接用”==”比较

  1. python数据类型转换(str跟int的转换)

字符串str转换成int: int_value = int(str_value)
int转换成字符串str: str_value = str(int_value)

Dict

Python 字典items返回列表,iteritems返回迭代器

字典items()方法和iteritems()方法,是python字典的内建函数,分别会返回Python列表和迭代器

Set

python中的set如何只取结果

Queue

python队列Queue

Debug

python代码问题 TypeError: ‘int’ object is not callable

比如在你的程序中使用了max函数,但是你又定义了一个与该函数同名的变量,那么就可能会出现类似的错误

P.K.

  1. Python 里面的 函数 和 方法 怎么区分?
    Python中Function(函数)和methon(方法)

  2. python 中的字符串连接

  3. Python collections.defaultdict() 与 dict的使用和区别

    原文作者:司小幽
    原文地址: https://www.jianshu.com/p/85b14632827b
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞