笔记 Data Processing Using Python 2(用Python玩转数据第二章)

  • range(start,end,step=1)
    (start,end,step=1)
    range(start,end)
    (start,end)
    range(end)
    (end)

     

  • for iter_var in iterable_object
     iter_var in iterable_object
        suite_to_repeat
    suite_to_repeat

     

    • 可以明确循环次数:遍历一个数据集内的成员;在列表解析中使用;生成器表达式中使用
    • iterable_object: String, List,Tuple, Dictionary,File
  • 自定义函数的创建方式:
    def function_name([arguments])
     function_name([arguments])
        “optional documentation string”
    “optional documentation string”
        function_suite
    function_suite

     

  • 默认参数:
    • 函数的参数有默认值,如果未传入参数则使用默认值
    • 传入参数则使用传入参数的值
    • 默认参数一般放置在所有参数之后
  • 传递函数:函数可以像参数一样传递给另外一个参参数,即function1(function2(x))
  • 匿名函数lambada x:x+x #与ES6的箭头函数是类似的
#普通函数 python2的写法
def func(a,b,c):
 func(a,b,c):
    return a+b+c
return a+b+c

print func(1,2,3)

#lamanda函数
f = lambda a,b,c:a+b+c
 = lambda a,b,c:a+b+c

print f(1,2,3)
  • 几种类型的常用方法

    • 序列

      • 序列的标准类型运算

        • 值比较:<、>、<=、>=、==、!=、>、<=、>=、==、!=
        • 对象身份比较:is、is not
        • 逻辑运算:and、or、not
      • 序列类型函数(使用时可直接查文档)

        • seq[start: end] 切片操作
        • 判断元素是否存在序列中:in,not in
        • enumerate(), reversed(), sorted(), zip()(), reversed(), sorted(), zip()
    • 字符串

      • 字符串类型方法(使用时可直接查文档)

        • join(), strip(), replace(), split(), translate(),startswith()(), strip(), replace(), split(), translate(),startswith()
    • 列表(数组)

      • 列表类型常用方法

        • append(), count(), extend(), insert(), pop(), sort()(), count(), extend(), insert(), pop(), sort()
    • 元组

      • ​​​​​​​len(),max(),min(),tuple()将序列转换为元组​​​​​​​
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值