婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > python內置函數之slice案例詳解

python內置函數之slice案例詳解

熱門標簽:不錯的400電話辦理 電話機器人適用業務 南昌辦理400電話怎么安裝 徐州天音防封電銷卡 鄭州智能外呼系統運營商 哈爾濱外呼系統代理商 佛山防封外呼系統收費 湛江電銷防封卡 獲客智能電銷機器人

英文文檔:

class slice(stop) class slice(start, stop[, step]) Return a slice object representing the set of indices specified by range(start, stop, step). The start and step arguments default to None. Slice objects have read-only data attributes start, stop and step which merely return the argument values (or their default). They have no other explicit functionality; however they are used by Numerical Python and other third party extensions. Slice objects are also generated when extended indexing syntax is used. For example: a[start:stop:step] or a[start:stop, i]. See itertools.islice() for an alternate version that returns an iterator.

說明:

  1. 函數實際上是一個切片類的構造函數,返回一個切片對象。

  2. 切片對象由3個屬性start、stop、step組成,start和step默認值為None。切片對象主要用于對序列對象進行切片取對應元素。

>>> help(slice)
class slice(object)
 |  slice(stop)
 |  slice(start, stop[, step])
 |  
 |  Create a slice object.  This is used for extended slicing (e.g. a[0:10:2]).
 |  
 |  Methods defined here:
 |  
 |  ...#省略#
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  start
 |  
 |  step
 |  
 |  stop
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __hash__ = None
>>> a = list(range(10))
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> a[None:5:None] # start step顯式為None
[0, 1, 2, 3, 4]
>>> a[:5:] # start step默認為None
[0, 1, 2, 3, 4]
>>> a[2:5:None] # step顯式為None
[2, 3, 4]
>>> a[2:5:] # step默認為None
[2, 3, 4]
>>> a[1:10:3]
[1, 4, 7]

  3. 對應切片對象的3個屬性start、stop、step,slice函數也有3個對應的參數start、stop、step,其值分別會付給切片對象的start、stop、step。

>>> c1 = slice(5) # 定義c1
>>> c1
slice(None, 5, None)
>>> c2 = slice(2,5) # 定義c2
>>> c2
slice(2, 5, None)
>>> c3 = slice(1,10,3) # 定義c3
>>> c3
slice(1, 10, 3)
>>> a[c1] # 和a[:5:]結果相同
[0, 1, 2, 3, 4]
>>> a[c2] # 和a[2:5:]結果相同
[2, 3, 4]
>>> a[c3] # 和a[1:10:3]結果相同
[1, 4, 7]

到此這篇關于python內置函數之slice案例詳解的文章就介紹到這了,更多相關python內置函數之slice內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python:slice與indices的用法
  • Python高級特性切片(Slice)操作詳解
  • python中slice參數過長的處理方法及實例
  • 詳解python編程slice與indices函數用法示例

標簽:吉安 安康 紹興 呂梁 廣西 蕪湖 懷化 蘭州

巨人網絡通訊聲明:本文標題《python內置函數之slice案例詳解》,本文關鍵詞  python,內置,函數,之,slice,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《python內置函數之slice案例詳解》相關的同類信息!
  • 本頁收集關于python內置函數之slice案例詳解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 金山区| 扶绥县| 西畴县| 广饶县| 溧水县| 旬阳县| 禹州市| 文安县| 子洲县| 昌都县| 鄂温| 宁南县| 哈尔滨市| 嘉峪关市| 鄂州市| 天等县| 尚义县| 垦利县| 临朐县| 普定县| 罗江县| 金川县| 大港区| 海安县| 漯河市| 新平| 尼玛县| 罗甸县| 湖北省| 冷水江市| 满洲里市| 车致| 临朐县| 武安市| 竹山县| 宁强县| 合阳县| 葫芦岛市| 郓城县| 高邑县| 闻喜县|