自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

講述Python序列如何進(jìn)行解包教程

開(kāi)發(fā) 后端
Python序列如何來(lái)完成相關(guān)的工作呢?這個(gè)問(wèn)題有些時(shí)候會(huì)困擾我們。在下面我們就來(lái)詳細(xì)的看下如何進(jìn)行相關(guān)的知識(shí)應(yīng)用。

Python序列具有很廣泛的應(yīng)用范圍,在實(shí)際的應(yīng)用中還是有不少的問(wèn)題需要我們大家解決。下面我們就來(lái)看看相關(guān)的問(wèn)題如何進(jìn)行解決。希望在今后的工作中有所幫助。#t#

Python序列(字符串,列表,元組)

Python序列的***個(gè)元素從0開(kāi)始,它不但可以從頭開(kāi)始訪問(wèn),也可以從尾部訪問(wèn),***一個(gè)元素是a[-1],倒數(shù)第二個(gè)是a[-2],倒數(shù)第i個(gè)是a[-i].

列表的創(chuàng)建,遍歷,修改等,列表中可以存儲(chǔ)不同類型的元素,習(xí)慣上都使用列表存儲(chǔ)通類型的數(shù)據(jù)。長(zhǎng)度可以在運(yùn)行時(shí)修改。

 

元組,通常存儲(chǔ)異種數(shù)據(jù)的序列,這個(gè)也是習(xí)慣,非規(guī)則。長(zhǎng)度事先確定的,不可以在程序執(zhí)行期間更改。元組的創(chuàng)建可以訪問(wèn):

  1. aList = []for number in range( 1, 11 ): aList += [ number ]
    print "The value of aList is:", aList for item in aList: print item,
    print for i in range( len( aList ) ): print "%9d %7d" % 
    ( i, aList[ i ] )aList[ 0 ] = -100 aList[ -3 ] = 19print "Value of aList after modification:", aList   
  2. 7.3.  
  3. hour = 2 
  4. minute = 12 
  5. second = 34 
  6. currentTime = hour, minute, second # create tuple  
  7. print "The value of currentTime is:", currentTime  

 

Python序列解包

atupe=(1,2,3)來(lái)創(chuàng)建元組,稱為”元組打包”,因?yàn)橹当?ldquo;打包到元組中”,元組和其他序列可以“解包”即將序列中存儲(chǔ)的值指派給各個(gè)標(biāo)識(shí)符。例子:


  1. # create 
    sequencesaString = "abc"aList = [ 1, 2, 3 ]
    aTuple = "a", "A",   
  2. # unpack sequences to variablesprint "Unpacking string..."
    first, second, 
    third = aStringprint "String values:", first,
     second, third print "\nUnpacking list..."first, second, 
    third = aListprint "List values:", first, second, third 
    print "\nUnpacking tuple..."first, second, 
    third = aTupleprint 
    "Tuple values:", first, second, third   
  3. # swapping two valuesx = 3y = 4 print "\nBefore 
    swapping: 
    x = %d, y = %d" % ( x, y )x, yy = y, x # swap varia
    blesprint "After swapping: 
    x = %d, y = %d" % ( x, y )  

以上就是對(duì)Python序列的相關(guān)介紹。希望對(duì)大家有所幫助。

責(zé)任編輯:張浩 來(lái)源: CSDN
相關(guān)推薦

2010-03-12 20:08:53

Python統(tǒng)計(jì)

2010-02-01 10:21:36

Python編碼轉(zhuǎn)換

2010-02-22 16:05:40

Python配置

2024-07-08 08:38:37

Python游戲開(kāi)發(fā)

2010-02-03 13:55:51

Python 代碼

2010-02-01 14:48:43

2010-02-01 17:33:24

Python主線程

2010-02-01 18:20:17

Python 多重繼承

2010-02-02 16:47:12

Python主線程

2010-03-11 17:38:20

Python中文

2010-03-15 15:11:50

Python列表

2010-03-01 16:32:36

Python語(yǔ)言

2010-02-22 17:12:34

Python對(duì)象

2010-03-09 18:14:55

Python sock

2010-03-15 15:45:15

Python編程語(yǔ)言

2010-02-01 16:22:36

Python字符串操作

2010-03-01 11:06:52

Python 調(diào)試器

2021-05-24 12:10:54

PythonSpaceX代碼

2010-03-12 17:35:00

Python字符串

2010-03-12 19:29:15

python svn腳
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)