zoukankan      html  css  js  c++  java
  • Python Learning: 03

        An inch is worth a pound of gold, an inch of gold is hard to buy an inch of time.

    • Slice

        When the scale of data is so large that we have to pick a short of the content, the best way is to use Slice.

      • Forward Slice
    >>>L=range(1,101)
    >>>L[1:]              #until the end
    >>>L[:101]          #from the first
    >>>L[1:100]
    >>>L[1:101:2]     #pick one in two
      • Reverse Slice
    >>>L=range(1,101)
    >>>L[-1:]  
    >>>L[:-1]
    >>>L[-5:-1]
    >>>L[-46::5]
    • Iteration

        In Python, Iterations are done with "for ... in ...". 'For' loop in python can be used not only on Lists and Tuples, but alse on any other iterable objects. Therefore, the iterative operation is for a collection, whether the collection is ordered or unordered, we can always use the loop to extract each element of the collection in turn. The collection is a data structure containing a set of elements, and we have learnt List, Tuple, Set, Dict, Str, Unicode.

      • Index Iteration: Using enumerate() to get the Tuple of index and name and using zip() to conbine two lists into one
    for index, name in enumerate(L):
        print index, '-', name
    >>> zip([10, 20, 30], ['A', 'B', 'C'])
    [(10, 'A'), (20, 'B'), (30, 'C')]
      • The value of dict: values()  and  itervalues()
      • The key-value of dict: items()  and iteritems()
    When you return with glory, you will be bathed in the golden rain.
  • 相关阅读:
    我的2015羊年总结
    谈对象 MVC 和 多端
    自建博客随想录
    梦说1+1等于多少
    多媒体文件格式全解说(下)--图片
    多媒体文件格式全解说(上)--音视频
    做一个“代码模块”交易的网站
    写个屏蔽百度搜索广告的Chrome插件
    Go 系列教程 —— 5. 常量
    Go 系列教程 —— 4. 类型
  • 原文地址:https://www.cnblogs.com/DrunkYouth/p/10362573.html
Copyright © 2011-2022 走看看