10.python中的序列

  本来说完字符串、数字、布尔值之后,应该要继续讲元祖、列表之类的。但是元祖和列表都属于序列,所以有必要先讲讲python的序列是什么。

  首先,序列是是Python中最基本的数据结构。序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推。每个索引对应一个元素

  Python包含 6 中内建的序列,包括列表、元组、字符串、Unicode字符串、buffer对象和xrange对象。

  对于序列,都可以使用以下操作:

  1.索引

  2.切片

  3.加

  4.乘

  5.成员检查

  6.计算序列的长度

  7.取序列中的最大、最小值


1.索引

  所谓的索引就是对每个元素进行编号,注意,编号是从0开始的。

  我们可用通过索引来取得其对应的元素:

  对于字符串:

a = 'scolia'
b = a[3]
print b
print type(b)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcMAAAA8CAIAAACVV0bxAAAG/0lEQVR4nO2dy5GrOBSGFZZCmERaYeC6AYx2Xt3JgG1r7yjYkIGTYBa89EZGgH1vf191ddluIR0dHf0cCXCLAQAA6hDvNgAA4I9nl5L2DykffW3TnRKNEK2prSfG51t4DaYVB/jhkLaeWuad2altV5eUeQelfj48og51yHnRcmUcvolQSceIvwlxE6pLHPXU8q4txxg1HyJu6oWB3RUH/UOKxm3LsnkaMN/CvXza1C0ZHaewMtPoKDP0+l524E7D5uFIOS3vzKf+2pxsJWWux+77JsdG1FPLo2p7qRcfUvMH4Stpr+9SP4dhGIZOpU8jVrFhKjzGR/+Q2UDp9cP6646osuaSaefTe6dnm81cXWBhKdUWnkjh6EysicDSi9O6Yycd/UOK6My5yJnuCJ571DC8mnC9P6LiPXV7caQPz6v5k/CV1E7lLOuD4feXz4VK6tWzI6rsQ/zDHXfvXODXW3gez9LRmQqHSeJJ3XGTDtMK1apI5nuNM/e1stu2VxOut0fUZrSkynxazZ+Fr6TlFhvlOchecU9vlRkzx5sQ7ff0YvxZJ7bWdyFua/44Ld5HyZj2lfwyY8EgL9ZuAdtCoxohWqWauZ4rLHSIHHXXvbtx5pQJeSWenEQgoqTrh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kiMwSlu3FQx4/+eP5hNnNc/cAALWgpAAAtaCkAAC1oKQAALWgpAAAtaCkAAC1oKQAALWgpAAAtYTP3UshhBDcsQ4AUEo0JzUKJQUAKAYlBQCoBSUFAKgFJQUAqAUlBQCoBSUFAKgFJQUAqCV1P6kQQki+RRYAoACecQIAqAUlBQCoBSUFAKgFJQUAqAUlBQCoBSUFAKgFJQUAqAUlBQCoBSUFAKjlvUp61GOpPN4KAO/k3Up6zBOpR9UDALCHjJIadW6e12t5iP7F6znbegCAhZSS+uvlXus3CtOu1lnyA8BFRJW019LToPeq0u7WWfUDwBVElNSXH6PEivqe3yuz/En9UkIIpZT7XXzTN/S9JmZra+NxXutL41PlWwobnhQAAI4mVNJoAuh9uIqt0eMLo0ZVWzctl1cvJYZlrb+gz6zxAeB0Cr8zP9w2lVL31mWdpYD9Ys0lX9Eyo/xMNlTSwgqRUQC4gsIrTvNbY+YPx9X1UsaoUfsiOekw9H15TqrnZFc5ldutF+ojMgoAF1F4F9T8T0niS/xhVFLp7Vwu/8nkBUGz/vtJtHUr082v77kLCgAuY/+d+a5UkQACwM9lh5Ja1+69j7jlCAB+JHyDCQBALSgpAEAtKCkAQC0oKQBALSgpAEAtKCkAQC0oKQBALSgpAEAtKCkAQC3/AwuPqYNQA3tHAAAAAElFTkSuQmCC" alt="" />

  注意:对字符串而言,取出的元素依然是字符串类型。

  对于元祖:

a = ('scolia', 123, True,(),[])
b = a[0]
c = a[1]
print b
print type(b)
print c
print type(c)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbgAAABdCAIAAABYVuRhAAAJNElEQVR4nO3dzbWzqh6AccqihNtIKCN7nQIOs4zu7cDpZp4qnNhBmvAOFOVT0KjJTp7fOus9SbYBRPwLaFT0a3V3Ke/d6q8FWiWuQjTm2XRS3r+E5zCN2KEedsnroeVyZbaqXNU1y7xCbT3v3qJ2rZDjWsuZ7fAwwn87NOgfIX6EajNfeWh50856G2W/In7Uiu22aTN3dymufl5OmcftEZZw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ZzBpueTpt6kEUbu5OP3V58M3lQQB2tPGCcz8S0X0D8MnWBkrnrHfwEdfiAPhQ3BQDAAoIlABQQKAEgAICJQAUECgBoIBACQAFBEoAKCBQAkABgRIAChKB0vt5Yvzza+cH1/xuEcA38ANl+APFTl/sDxONGm/cO/1UsdOSUAngCyzfjzL3Ov0BAHykmhv39n34tEOjGHgD+BpVgTL3TFhiJYBvUA6U9vblMSIlgK9QCJTucww7rb2TOfkICgCfJHnWezrz7T0uNnqELN1JAF+BC84BoIBACQAFBEoAKCBQAkABgRIACgiUAFBAoASAAgIlABQQKAGg4IWBcq+fivOTcwDHemmg3OeWRMl0AGA3uUDpPQ/iAOk7t3n3VH8inaNLD+CrJANl2K3rtH6ruFNRHsbjAHYTB0r3zmqDdws6leVhSA5gH2GgDKOLd6M19es+fsy+/EcJIZRS853Y+n56fOOaWBU+2mx4r7SWc0J+eQrhMo75ALBeECiTnbXgwzmWGj1HL2XcCcPp1dpuXZTXGCIXH3NWmxoAbFHzzJx4ylJK3TlnTKYF3Bfbnv4dB8og5WQJa5ICgI1qTubYt8bMT4WQwRhZ6i7Zo+z7rnuuR5kPlHN5iukAwHY1lweN042Z8Xc/BEop/UXsl1bEq9yDKJTxpy9T5cmXHgCetPGCcz8S0X0D8MnWBsrwzPT8EdfiAPhQ3BQDAAoIlABQQKAEgAICJQAUECgBoIBACQAF/wdXTSBJKnTz9gAAAABJRU5ErkJggg==" alt="" />

  取出来的元素原来是什么类型就是什么类型,为什么会这样呢,看下面这个例子:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAABrCAIAAAD/8SkeAAAHqUlEQVR4nO2dTWvjVhSGz18qE/D9LRnwps79GSNBlgYxq9lHgayyMlUXXTVOZ5FdmIW9EF0kzhScwjBM24ASO6cLfVoflizJsn3yvrwEWZbvh+6jo6MrOabv37/f3t4yBB24CChDMgSUISECypAQAWVIiIAyJERAGRIioAwJUTHKDxlD0B4LKENCBJQhIeoIZUcTEREpy2V2LeW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TqCFCOQoAACUqvVGXRo0/5CuatXTnfFLpN8YYYwUkKlgAwIfQlkbtj0l69AL+m1nLRYIUEikA4DN4KI0mD5vyNBo+msKTKQDAR7BHGiUl0mrUmHlGNQoA+ARKadT2OIU7o/siMzysu06pWruj7joUowCADwGv3wMAQBdIowAA0AXSKAAAdIE0CgAAXSCNAgBAF0ijAADQBdIoAAB0gTQKAABd/AFmO66RGnouMwAAAABJRU5ErkJggg==" alt="" />

  竟然是同一个对象,也就是说变量 l 和变量b 指向了同一个内存空间

def text():
print 'scolia' a = ('scolia', 123, True, (), text)
b = a[4]
b()

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbUAAAApCAIAAAA9GyAGAAAGEklEQVR4nO2cwZnrKAzHVRYlbCOhDKeC5ebTbge+DvdU4Ys7SBPeg8EgEJg4tid5+/9978ubOBiEJIRQPEMzAAAACXqt+fRQ6jG9O+ioqSMa7Lv9SHy+hNdgBzpAD4eM9TSqrsxRb6u6pc1v0Krnwz3qUIWc5y1X+uEJxPFx8eM70Z30WGj/NKo30XSt9rfQXb9grl3WnR6KOj5WJLMzQyrhXj5tQbZYhzXW1llH23kyfduNOwXz5igpra7Mp7ltLqGWNtcTz32TYz3qadRRvb00iw/p+SJCfJxMr8xznud5HnU55EfNZtd4sfr0UFXzT+YRfbrDV6IVYge/FY/Gy2x9d5mErbwt4Yk0WscRNu11FqdNJ04QpocicT1cpExuwXPvmudXk6Pf9yh5pnwWR+rwvJ6vIsTHOO2KZMqMmh5gG+Nj0s8OX4lvSW9nStx5xH5fwvN4tlrHNc4TupOmwxMEO5AetJClXqPMfaPslu3V5OjXPWrTW0ptPq3n6wjxsV0Oq5Npx2de91bbJcu7Ew0/7oflX1iuxvRE95DruePzEghcvSZtszTMcljDG8QSWt0RDVp3vp8rJGQId/Vm4gUp1ibnFS9hm7YQH0NJhOd9bnSvE+sulu9Kx1rUzs99S2+qVzT8Y3qiXqmO1HBTndPYOlwQONNq2kaSh1vwpzALV2dY6zO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NSfERAAC+HsRHAACQYfHRanIofzr29UWK/vKiYi3mND66XvjfBsy6AQCADyeOj1IZUS2X1o8mo5SZwv+FG5Mr61tkmgCAryE5Xy+53xr5KoEv/mgzPsapKeIjAOA7YPmjcXExzhbXn8wB+WPoDwAAPp04Pq5FQmKpIS9IJvXH6B5/KaSKUSx0ientpnjpEgAAPhX8/gwAAMggPgIAgAziIwAAyCA+AgCADOIjAADIID4CAIAM4iMAAMggPgIAgAziIwAAyCA+AgCADOIjAADIID4CAIDMfz7henLK0bQiAAAAAElFTkSuQmCC" alt="" />

  里面放函数也可以,那么这样呢?

l = []
a = ('scolia', 123, True, (), l)
b = a[4]
b.append(1)  #append()是列表的一个方法,将一个元素添加到列表的最后,对原列表进行操作,但返回值为None
print l
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcsAAAA5CAIAAADWTZe2AAAGKElEQVR4nO2dy3XjOBBFERZDmESMMKgIBjutejLg1tgrCm6YgZLgLPjDn5DEotnd954+Pm0bBAqFwmOhRFlqBAAAGdRPGwAA8MeCwgIASPGxwg6PpnkMn/bSa9Uq1dlP+0lxfQvPwXbqAD8cMtbTNGVn9nrf1TVtfoJaPx8eUYc6RC5azozDC1BW2Gkn3JS6Kd3n29yN4zCrl0vUTb+w4G/Fx/BoVOuP5dg8L2Ro4btcbUvXrI7XWNt5dbQdB3Ovu/BNw5blyDmt7Myn+drdhDVtzsed+y7HRtTTNEf19tIsLtLzRSkp7GDujXmO4ziOvc7fdpxm49x4ipvh0RQDaDAP57dvRJuzx2y3pAO9WWy2S3eRhbV8bKEglaszsyUO6yzEpuMmKcOjUckddZIz/RWUvWocX03Qfj6i0jP1Z3GkD+V6violhXVTP2dWUViEx/BKhQ36eSPa3EvCy71leLNQ8LmFcjxrV2duHCeVQtPxkxTbKd3pRKZ8jjPfG+Vt215N0H48onajJdfmaj1fl5LC1s/E6sBx7sl9/lbbKdO8KdV9z/+Z/m0b3pi7Urct35yLAJOUzHWrsM3UMMqjjd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b2Wrv7hHfN9ttreddgftHZy3mvZSH8nUSRWcNavjzkbTW/PVfb3fxdAgAAKVBYAAApUFgAAClQWAAAKVBYAAApUFgAAClQWAAAKfYV1mqllFKqST9tN5hm+j1PkwIA+FQorKl5kHkwBoUFAPB4R2GtjvNVFBYAIORFhZ1LBigsAMA+b+SwVqOwAAAVoLAAAFKgsAAAUqCwAABSoLAAAFK89yxB/DwBCgsAEMJ7ugAApODvEgAASIHCAgBIgcICAEiBwgIASIHCAgBIgcICAEiBwgIASIHCAgBIwTsOAACk4FNkAACk4FNkAACk4FNkAACk4K8XAgBIgcICAEiBwgIASIHCAgBIgcICAEjBp8gAAEjBe7oAAKTg7xIAAEiBwgIASIHCAgBIgcICAEiBwgIASIHCAgBI8T/2Ndhs2EZe1QAAAABJRU5ErkJggg==" alt="" />

  我们对取出来的元素进行了操作,竟然影响了原列表。

  这说明了:

    序列其实是一个容器,里面可以放任何的对象,而当我们通过索引去取的时候,取到的原对象。那么我看是不是可以将索引看作是一个特别的变量,它指向的也是内存空间,当然这个说法套到字符串中略显变扭,我们只能假设字符串是将每个字符都存在一个内存空间中,每个字符都是字符串类型,变量取得的是整个字符串,而索引则是每个字符的变量。我们看看这个假设的结果如何

a = 'abcdabcd'
print id(a[0]),id(a[4])

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeoAAAAoCAIAAAC+WC5mAAAGsUlEQVR4nO2dzbmrOAyGXZZLmEaiMkgF411WMx2wjfapgsXQQZpgFmCwbBmcHMLBN9/73Of8ENmWbfFFCHKuGQAAAFSI+W0HAAAAvMNO8t0/rH30P+2lI9MY0/IeHsWc38Nj4NbssA67jPV0dn0xO9pe6hKb36B0nXePqF0X5HPRcmQc/rmUyPd4ml2NuRrq8jY3F+wGk29irvRCNL0VfP3DmkaOFfg8RUns4bucTS9KdkcYE0+7Qzz07lbW8E3H/HbkFm19MZ/usnmGl9gcTzj3TfaNqKeze/X20ixO0vN3sS3fvbtZ9xyGYRg6yr9hBmbDZD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F7IMezgolEVXI+eq402rf649sbu2O9iBEXO1VH0AMRw8KjsH6JK301FvcFeDBZ7vUkmmM/dtXh6evQcE3vnciVjW2ycwi3EF9FnMtvr3YJnjStNFWI6x9y360dWZqeXgyB2PFe9o51zkRhzIycz7r90Xk1qfx43tTNlHfQc0m7jkTvYf1rL8ll5zddbP7py7TyxyBVtA4mNnDXHr+6x7uy5HP2H7z87w7zn2zMpBn6zndLf6YZ72/4uw+7EPz3XLn9xxMjyiIbP1cHoLvJInMEuaS8S6fTaueLzm78TdPAACgSiDfAABQJZBvAACoEsg3AABUCeQbAACqBPINAABVAvkGAIAqgXwDAECVQL4BAKBKyuWbyfiPLDEZD/m/5WXlgfCQsa5XbAKD2SZtFRza+sTU+T0EAIDdKJVvplmdmLxsDb2zhu7jN/Z2/ic3WTGzNxU2PXP68d6o1TAweZUM1LlODwEAYEfK5JvJECnaNOlVKFuxhPXOcXycydBdF8eoVe+sLfobDuf3EAAAdqVEvsdkNlK9INkN8tbeWVlCmHPV2OY+sLtcbFSGiFsxGXLbpYnzewgAADuzLd9MlCSny2tzuWISucvFhmazymk2y4tL/SFqxRTWnDNp7vk9BACA3Sn5vy4FUiATxZQHvLBKFJkVh4JWvbPZokfQ9uQeAgDA/rzx5ElwY5DJWPefTHGFNioV59km7qdXWgWvbOe25/cQAAB2o0y+l4flrOvDfDd+Km8l0VVsln5EYULmsHO7VWk8v4cAALAr+NgOAABUCeQbAACqBPINAABVAvkGAIAqgXwDAECVQL4BAKBKIN8AAFAlkG8AAKgSyDcAAFQJ5BsAAKrkf7tuFt/CMQbxAAAAAElFTkSuQmCC" alt="" />

  好像假设成立?

  那这样呢:

a = 'abcdabcd'
b = 'a'
print id(a[0]),id(a[4]),id(b)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAawAAAAqCAIAAABgNPiKAAAGlElEQVR4nO2czbXzJhCGKYsS0ogpQ64g7LxKOtDW7F2FFlEHboIsBIKBAWFbkp3wPifn5ruYn2FghmEkX2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="" />

  看到这里你是不是明白了什么。

  字符串是字符对象的引用的集合,所以我们使用英文的时候是不是最多只有创建26个字母,然后字符串只要重复引用就可以了。其他字符也同理。

  我们对于序列的了解就更深了一步。


 2.切片

  所谓切片就是一次拿出多个对象,而索引一次只能拿出一个对象。

a = ('scolia', 123, True)
b = a[0:2]
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbgAAAAnCAIAAADy78rGAAAGoklEQVR4nO2cy5XjKhCGCYsQJhEThhzBsNPqTgbaNntHoY0ycBK6C4GgoHhYL2vu/b8zp09bjaAo4KcoySNmAAAARcS3DQAAgLuzQyinl5Svaa8BoxKdEIPZWw/H/S28BjOIA/xwSFtvLcvOHFXd1S1lvkGrnw+fUYc65LzZcuU8PJqcUC4T+inEU6gxX6bXQb+NcreIp/pg3DYN8/SSoqNtBTbb8Ygt3MrdVmbL6JDCytjRUWaedN9240bD3HDknFZ25ls/qmuppcz1hH2vcuyMemt5VG0f9eImNV8BL5ST7qV+z/M8z6PKbwJBsdkWXoZ/esniPJj0K/jrhkkTLBUzuM151M5m46pLLGxlt4Un0jg6Fr+Nr704rTthyDC9pGAXxkXOpCN47l3z/Gm49P0ZxfeU9uJIH55X8yXwQhkGYoFxyejGZ9tGoYzq2TBpwlvi24k3N56+91t4Hu/W0bGF0xDvpO7QkMEMQg2KiVuvcea2Vjbb9mm49PUZVZ0tuTJ3q/kieKFsN8ioqP/hcdh+VGaJ+55CDD/2l+WfX7da90I8ffRnT9aLIticTlxmKZhEtZoWCC00qhNiUKpz9VxhIYG5q9cTTVqRMimfTBeyjTNC6bMlNBK0rTufGHsxf1fc1uJ2eiRcapO9FMM/uheil7ITcnjIznpsbc4bnHg1LsPZQ0fwJ9MLm4JYUzfMuDd5g/Z9VKJTahDiqdSQH9NRkXmYzMxcW+ncSB2SllnzVMu+xfY0GsGqN9jZe33N8TSorO7NOrtXKGczBNmudA37s6HR6YpdP3auY8t1FzT5eDAtM8/sydq8Yn2JLeyUoTWfaSF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eKUNhW7nf2ApQSAGDZJZT+2ErisjiMk6REUnMc9/HVbIXvBT3MG8W0BKEEAFj2CCWXarTH1/VPTpGIMqU3RlfWj/vViqmBT3kiogQAZCjnKKsPNJZoMHgynlXA4rGXPQgzj1g2wOhfple0JB58AwAcxafeFaU02v41jB/X3/QBEWX0gKV0S74PQbFQ/SatycMcqqDQSQDASvt7lCnpuzY+EvS30RxlcI+7xL6gY0PVx0OKTATYHO/6moPPa/Ns6AqZBAAEtH8z51Yc+15nUvkduwwA+Br4rjcAAFSAUAIAQAUIJQAAVIBQAgBABQglAABUgFACAEAFCCUAAFSAUAIAQIV/AZqL23rBwi3jAAAAAElFTkSuQmCC" alt="" />

  返回的依然是一个元祖,这里要注意一个问题,那就是 a[2] 明明是 True 才对,但结果我们并没有取到,说明切片是不包括后界限的索引的

  另外,我可以只写其中的一个:

a = ('scolia', 123, True)
b = a[1:]
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbkAAAAhCAIAAADLdELlAAAGPElEQVR4nO2dy5XrKBCGCYsQJpEmDDmCy86rmQy07do7Cm3IwEloFgKJguIhW1K3Z/7v3NPHdkNRvH4KhPuqucbT6kGpm1I3ZaZymrt123syIYu6GaqaZ0xGjTuSL7iHVgMvK/JZP5zk4au85OGJ9PQOS2zI946h2dl7X8YXHQvdUWq0emM+7dej1WM9aa4nrnuTY0fU0+qjrO2qxS+xfDqq8jtn79o+53me58no4riMks0+8TIC3ENXh4Kzj+i3L4ybaLbQqHz2yQafKZjLPOzlbQ9PpLN3PDSGlWOtxWnV2cryi5k0Ny5qTN6D5+aaZ173Nj8/ouSa8loc2YbnWT6fmlbG4VjkX9bB7qHZ+OjUysTOC+MmzpJmZw2aeviC/dc8PI9nb+/4xHmgd1J1eOBAozKjEaLXaxrztVJe9m1v0PTjI6o5WkppfpvlK6hpZb9PZJImiPfF/q2hJfq7KTV++xfLv23qWntX6rbFgH6LvYjCYidLsyTMYlvLE8QekhmUGo0Zgp0rPGQIue7W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sXHc97svkArAQDg44FWAgBAG2glAAC0gVYCAEAbaCUAALSBVgIAQBtoJQAAtOnUSme/PuXy1ge5CgD4GLq0koz+JPlxVuNaOQDgUDq0MpMeMtF7Z7XyhL8AaFTySQdRpj3ZitY+StwBAL+etlaSibTLS1r0x33WDS8Zpcx3LFPO6l7Zc9bSWhTZt4WOOQ0AAO/S1MpcdeJPSq8LWculEEUZiN7WOYglAOBI3tTKDWd1tO8l88pWOrK8BrB+j28oMsqs+wTJphtaCQA4kmO0kgtlJeGussikGrgmWF+sJSdHlNBKAMCR9JxXNkI2MmlQV0rZLirVypJMxy+kR0J4FA4AOJSO5+CpWDIJi0XJWcue7Wwi2ima3VpJRqVx5Tw7t/33M5BKAMCh7Lxfmd4HYld9VNgNZ4Fezx2ecPkoNcKC1nB6abYTy/XSUqTZUEoAwLFc8L0d+TDzNPC9HQDA8eD74AAA0AZaCQAAbaCVAADQBloJAABtoJUAANDmXx/E3F19Vlr6AAAAAElFTkSuQmCC" alt="" />

  表示从某索引开始(包括),取到结束。

a = ('scolia', 123, True)
b = a[:2]
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAa0AAAAmCAIAAAD4NFPPAAAGmklEQVR4nO2cy7XjKBCGCYsQJhEThhzBsPNmZjLQ9rJ3FNroTAJOQr0QCAoKhPWyu/m/0+eea10eRVEURQm3+B8AANpG/AMAAG0jJgAAaBv4QQBA68APAgBaZ5MfHJ9SPse9XQ9KdEL0Zm87HN8v4TWYXhygh0P6emlZVuag1lVdU+YT1Or5cIs6VCHnWcuVdriJ1A/O9noX4i7UkKn10vKhg2EZ5aqIu3pjWjbN4viUoqN9BTJbdccSbuXbFl7N7JDCytjZUWYa9aOu4kbB3HTklFZW5kvfVpdKTZnrCce+yrEW9dLyqNbeGsWXtHwYsR8c9UPq1zRN0zSovAsPik228Dy741MWp3nUz+CvG2wiWAmmd1vroJ3MxjWXSFjLbglPpHJ2LH4TXkZx2nDCDX98SsHa/UXKpDN4bq1pejfY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Jvl0GzP4OkWJxfJlqNy2RGEc4gP4olX9nfZBdctOo4bYT5QdoOp2ejejO9jAn6iud00HrQxA6pZeZk5nPHdOpT+3GtMZPIzyBXJm45Y72XtczvbTWrO8vO75OkESyBO6tezCJhLmD8uITHcuVdrd/gXthpHDj21UNfnrVramv8MXcG967uk75XN/j3Nd+BfbFI4sfvkhC0SWKZNSxptUO+LPDbs3914/vFAIDWgR8EALQO/CAAoHXgBwEArQM/CABoHfhBAEDrwA8CAFqn4AdHfZsvJxklPnjN7srelyEDABoi6weNks4lBL/uYNRSCCFip7bq5o7pvZZRS1ytBqAxMn7Qu4NRywP9UOr1yiHYrt6NCvpybth7YqNE9MQ+vtLvAgA+D+8HTzuLXnXItT4u+I9pbj66FUL9hO5u1DKU6rNpAADA5bB+8DxPcKWPCfvK/c4+gCMEoC02+kF/piRRVRyESVIiaTmO2vhmtsKPgp60jWJ6gh8EoC22+UEuzWfPlsufnMMhjietGD1ZPu53RkwLfLoR8SAAbZPLD66+K5hjueCdctbBFc+k7CmVeXuxAca9ZUZFS+KVMQCNkXlfvOIIjbZ/DaO/5Td9QDwYvbsoVckKGRYLnduoNXlPQh0k3CAArVFzfzAlvYTi4zhfjeYHgzruEXtzxQaat5sUmfitOlr1LQefl+7ZwBNeEID2qPk+yVdx7H3GpPFvHDIA4Fzw/WIAQOvADwIAWgd+EADQOvCDAIDW+QXN/TAjimYprAAAAABJRU5ErkJggg==" alt="" />

  表示从最开始,取到结束的索引(不包括)。

  另外,还可以使用负数:

a = ('scolia', 123, True)
b = a[-2:]
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAccAAAAgCAIAAADoqCRrAAAGZElEQVR4nO2dwZXrKBBFCYsQJhEThhzBZ+fVTAbaNntHoQ0ZOAnNQiBRUCBkI2z3f/fM6dPtj6AoiqeipO4RcxPsXcq7fbWXSYlBiNG0sCjm8y3sgxlFAz80GeuhZdmZk9p3dU2bd1Dr5+YR1dQh50VLzzjsjqhos0T/VYirU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3r2Yyisaqm9sz5FUx6Js8AoqsKq1z286B0FGCpV9Oea8aqz1XDGHMWMjtlm2laF854Yy5Eb8+eUyp39ykcerNq96i1HrH9Jem51Yw0qfQt1bTdptREah9MnSVs898/283typUOWQuXBjcpfbXlRAtX4aCQCtd6xJu4umr5nba91eEeSceVRPYNrXD0oJgV+Ce5ik9UScXZzD43VKMSg5B/fOXRfQ2KiXFdnng1bpOZRbiC/CzWOu94kUPwKt7AeSOsq9J+OD8bNZr5YUwwVrymk9aTJnFIIzNnM19zp0ufxo/vjVlEfgW5NnHPmejt1jN/p6zZ3adQo6qHSHN1Ancq78xqYS6ZfbuFben5buAvfw+xSMO57x5v8+y9yLjHr3lH9Z27u7mq5pi2Z3CfgXtYTHLbz7IQ/J0kkVnDWo5s8qsuX897d3c3VQUAgL8CqCoAALQEqgoAAC2BqgIAQEugqgAA0BKoKgAAtASqCgAALTmkqlZfvuVluC8yFQDwqzigqkbJbxIqqyVe6AcAdKdaVRORMir42WopHP4vVCoRfVJBcNGRy7K9fdVtAADwK6hVVaMClXPiF/yhqPW4bZQQ6icUNKtlrUBarc06lNEvSyIxGgAAelCpqqk+hZ/kvs9cmh/FmOACY15WRMgqAKA3TVR1w2oZnLqNeuYgH/S8JsWuwqBM0Cnp3TWIjvxQVQBAb1qqKpXUQsNDYxkVq+XaYP1mHTkqpUJVAQC9qa+r7qSBRsWJYq7l/lCxquYEPfyGe8iF1wAAAN2pfgcgllUidqF8Wa3J06pNbivltVpVjRJxrjrP1m7/GyeIKgCgO0+9rxq/NUVeiBL+LJ4kjzVvOvlXtOJOSCLsq6xqq6yur3YF6g5NBQD0p9vvVvFF19PA71YBAN4D/g4AAAC0BKoKAAAtgaoCAEBL/gfW+8ScZN0dmQAAAABJRU5ErkJggg==" alt="" />

  正数表示索引是从左向右计算的,而负数则表示倒数,如-1就表示倒数第一个。

  但是,取对象的方向还是从左到右的,这里要注意下。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANYAAABSCA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ynRiUGIf/4jJ77GSXp0nw3GdW0TKEX8QzyvVjzp+NNDtFLZgM3GnG+ktbDjbNRo7EvY6K20jmdtJ408UPqmSWb+Vw2nfrcf3xtzCTyM8iVSWsueO9lNfP7X8/q3syB39vJo2UCdy6+mNXCUuD5cQuP5cp32X7xe3Nvc2DfmwfMMq1X9Fr8Z96pPGt1X/Adxyk8h/oO3ANTEod+l4Xg/0nmmT2sab5DvnDx6zlvdeP74AAA0AZaCQAAbaCVAADQBloJAABtoJUAANAGWgkAAG2glQAA0KZTK2d9W17eMkp88DXEK1tfuwwAAH1aaZT0shH9+gazlkIIkQpfUwqPab2XWUu8ng4AsNZ2aWWQjFnLA7UqV8Z6KPdW60ZFbXmpDmptlEiuuMtXajMA4Htpa+Vp596rDtROB6P/kOgWomQh1E8sibOWsVWfTTkAAL6GplaepxZX6lDcVul39gLEEgBg7SFaGc6vJDpLgzlJSmQ1p9EfX81e+F7QU71RTEvQSgCAtUdoJZd2dOfY9U9elIg45TcmV9aP7wsWUwOf/kRcCQDg6MlXNp9vLDFh9Ky8KILV8y97ImaeuOyAkcBCr2hJPAoHAFhru56DN8TSaPfXOIpcf9MHxJXJ85baLeU+RMViAZy1Js92qIhCKgEAC1vfr8zJX8AJ8WC4jeYro3v8JfatHRew3m5SFOLA7qg31Bx9XptnA1goJQDAs/V7O1/Fse97ZpV/Y5cBAJ8B3wcHAIA20EoAAGgDrQQAgDbQSgAAaAOtBACANtBKAABoA60EAIA20EoAAGgDrQQAgDbQSgAAaAOtBACANtBKAABoA60EAIA20EoAAGgDrQQAgDbQSgAAaPMvktanQ/Og5oEAAAAASUVORK5CYII=" alt="" />

  此时的后索引就成了-1了,在使用负数的使用要注意。所以所谓的后索引就是最后一个元素的索引,而不包括后索引就是不包括那个元素,只单纯作为分界线。

  但如果我这样写呢:

a = ('scolia', 123, True)
b = a[-1:-3]
print b

  开头的索引在结束的索引的右边,是不是就可以倒过来取了呢?

  答案是:

aaarticlea/png;base64,iVBORw0KGgoAA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bhDxqrRNXEnPxJcq5otFzsSzJsOKxovyXjP7jXoa/IyHLMic39Xg3UBGRt3SpfvRMPzTHl3qgpw4KWn3KkXL/Sg1aY0H6JlN35u5YO97btufspMqr+80Un5LtPbwOturZrEewzmHHjHuxOQVpM+l+Vd9e7TKSMM0OLpGQIwiULkr6e/i2407bxNRZh00otuxyEXV9rhjPaxudWfPcVXSsabj5G+GS6209WyNOjrapPHPegknP5BlDdFXBymU9d0pHDpZqNe25Zqz63Db0MSchs1K2maZ154w25oL3tuw5pXJ1v5nCCbDdLdu6VfeXpPtfa2gS6luqcbutqZHUVpg6Ttjmv3+2m+GdK02yEi4Neil9NedCCdeAQiEVtHWrOHJ12/LZuz3rcI/I40ole5IsHD0olgX6Sa7iE1tS0bazzyWVUaIT8l9f2XS/g2JlXPcnWo3bZGYRWpCfxVpHNjfZBUcGO04bYd2W9sPp2Spj54e1wVixTUetR038kHpmTma+pk9Nn/qP740xIm9Brk3cc8Z7m/XM30FrVvebefGzZGnOT+B2941ZJcwlv2+X8Fxanm38zecoT5z77jY5z96Byz3+mjO237G6L/rk7rg9E/wM3MNrkgt/loTgd5J4Zg1rufOUj/B8Pd+yuvE9CQAA0AJEWwAAaAGiLQAAtADRFgAAWoBoCwAALUC0BQCAFiDaAgBACwrRdtK35TDf+gcAAICDZKOtVTL4AhQtP+2gMAAAfBWZaJuEVxJ8AQAAPAkfba0ScS7LvAUAAKAWNtqykRXhFgAAjoNoCwAALUC0BQCAFuTqtskzMRxLAACAF8icSUjCLYItAAC8As7bAgBAC/BZMgAAaAG+JwEAAFqAaAsAAC1AtAUAgBYg2gIAQAsQbQEAoAX/A0Ss47HwYpjqAAAAAElFTkSuQmCC" alt="" />

  不可以,得到空的。看来一定要从左向右取对象

  还有,当我给的索引超出了呢?

a = ('scolia', 123, True)
b = a[0:100]
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbUAAAAqCAIAAAC7j1KoAAAHKElEQVR4nO2dPZbrKBCFWRZLm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sst/Q9fq5DnxpBHgG4JOXn1wsCOT+ZiOOj+Te9Q/xYe2bSKGekWixEVmvyfCYI5xbLtU4ZJdL4cRytDf8LGcgjAFel8f3HnPxlmRAhhctoxi26JpKjPKZygentJrNkXYtr1BlvmbyWI/xJl+nD8vs2vh+pEeKsz0aqkIFk87NQRwCuSuP3Zy7Fvu9jnmO50NwVhxcA4MD3rwEAgAf6CAAAPNBHAADggT4CAAAP9BEAAHigjwAAwPM/+yLDHavhutcAAAAASUVORK5CYII=" alt="" />

  python能自动处理索引超出的问题,这也是python优雅的所在。

  但是要注意:

a = ('scolia', 123, True)
b = a[10:100]
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaMAAAAuCAIAAAAKruERAAAF1ElEQVR4nO2bwZXrKgyGKYsSbiOhDKeCyy6b924HbId9qvDG5zaQJvwWBhuBwDixnYT3f2fOnEkGCyEJIbAt/gIAQOuIdysAAACHg0wHAGgfZDoAQPuIfwAAoHXECAAArYNMBwBoH2Q6AED7bM90w13K+/Bqv70SnRDGviqH4/M1PAdrxA522KWvh5ZlY/Zq3dQ1bd5BrZ13j6hdDXJctJwZh3miTDdF5FWIq1B95pKHljcdKG6Vv0Rc1QbDP+Wn4S5FR/sKdHYGjTV8lk+bWjXeIY2Vdd5Rdhz0re7CJxXz7sgZrWzMh76sToaaNucTjn2VfSPqoeVe0jaN4kMkb4NkukHfpH6M4ziOvcqn4aDZ6BpP/hvusujIQd+D/z7h9SDWrfHLY6+9ztaLSzSs5WUND6TSO45lIZ1HcdhwwkV7uEvBRvZJxqQePPaqcdxasLw/oviR0lHsacPjJG+EZLqwFAqkJ+6Jt4eVmS6S84TXw0viy4k5ntzAvq7hcTxqveMap0XWQcOhi7Y1QhnFVI7nGPO5Xp7WbWvB8vaIWo2WXJtPk7wZkunqJVoVDSDcUbqPyk6V11UI8+P+mH6Wiaf1TYjrUn+5zek0pd25RtxmapjUlZo2CDW0qhPCKNV5OWdoSGCuuumBHtyQNilb/E0WUib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QDaB5kOANA+yHQAgPZBpgMAtE8u0w36Mj2sM/8BAADfCp/prJLBy+Ra4hFbAMA3w2W6JLWRxAcAAN8Gk+msEnENx3wFAABfQ5rp2KyGVAcA+GKQ6QAA7YNMBwBoH/acLrn/gNuvAIBvhrv3mqQ6JDoAwFeD5+kAAO2DdyQAAO2D914BAO2DTAcAaB9kOgBA+yDTAQDaB5kOANA+yHQAgPZBpgMAtA8yHQCgfZDpAADt8x/z/V0ajxd9vwAAAABJRU5ErkJggg==" alt="" />

  这样就取不到了。

  最后,还有一个小技巧,虽然切片得到的是一个元祖,但能找到我们切片得到了几个元素,如果此时我用多个变量去承接呢?

a = ('scolia', 123, True)
b,c,d = a[:] #这里能得到原序列,此外还涉及到深浅拷贝的问题,以后再来解释
print b
print c
print d

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAb0AAABNCAIAAAC9qS2+AAAHmUlEQVR4nO3dTZarKBiAYZbFEnojYRnWoMfNLKPuHTgt5lmFE3eQTdgDUflVsNSbpN7n5NxblUJEwE9EY0Tzt+bFixcvXuUvMQAAahA3AaAOcRMA6hwXN/uHlI/+p7l0SjRCtOaIEoVev4TXMK04oB4OWddTy/XK7NR2VZek+RNK6/nwHnVohZzXW67sh0crjJtj//4S4kuoLp/mrp1qMGpaRHypimbc1er9Q4rGX5dTZts8YQn3erUdtaR1vMTK2NZRZuj1vWzBnQWbmiNXaeuV+dS3zV2rJM313G3fdGyPemp5VG5VW/EiOV+hKG72+i71cxiGYehU/hDhJBts4rE39A+52i16/XD+uqMPOXuOaadDd6enMpspu6iEpX5cwhMVto61HOTnrThtc9wBRf+QIrmfXFSZfgueu9Qw1A6m/nyPSm+pvxVH1uF5OV+iKG66wzSnrFFjhyfChXEzyGdHH3IXCRf3KnfnqfrPS3ieZ2nr2MTxAPCkzfEHFKYVqlWJUe01lblvLbvLVjuY+uM9arO35NK8Ws4XKYqb5eUzKqgO99zZ/qrMOCr8EqL9tj+Mr2U31vouxNcyNrSn4WOAs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94CY915b1y731f3s8cuO2bJ6F5W7f9bfmYezZP3Luv/Jxlt1zPeg32wqs3Pn2tEuJ3inpmiXla8JAPd7y9U/duPp8OAHWImwBQh7gJAHWImwBQh7gJAHWImwBQh7gJAHWImwBQ58S42WsphBAiuM/UqPAdAHgnZ4834yjZ6xsfZwDwxq6PmwDw3oibAFCnNG4aJSw5nWVP85fCefKl9FIMYdy0ufjPZoyyAYBXVhg3U9OUcnxr/lOvpdT98n9mweCd+VdGpgDeQ/l5+jhWnCPiSkB0/7QZN92hLHETwBsoHW9qGy/d0eX8kz5gvLnkBwAvrTBuzpOQwhtK+hOewfyms8z01jK0dGKkHcjebtKfGgWAl8TnhQCgDnETAOoQNwGgDnETAOoQNwGgDnETAOoQNwGgDnETAOoQNwGgDnETAOoQNwGgTkXcNMp57kb8gfXkZ88B4OOUxc3wecPOdwQZJYT6HozynmdM5ATwsaqev5l8qmbqeZqETQCfa1/cXHgP2xzHpQRNAB/tR3HTD5orCQHgc+yPm0blnjJM4ATwyXbGzV5L5yKR9q4L5QMqAHyAquvp8zV15/f5SzD4ejUAvwP3vQNAHeImANQhbgJAHeImANQhbgJAHeImANQhbgJAHeImANQhbgJAHeImANQhbgJAnaK46X0cnU+fA/jdiuKm1mZ+HpLRPOsIwK9WNt60z0Aan4VkGHAC+M12PX9z/po2+62WyjhfkeF9V4ZNwPM4AXyO3c97NyqMh3OC+Yf5ezScpxoDwJv7SdwMrhDFcdO9nsTlJAAf4oS4aZQIx5vD0PeMNwF8hsK4aecpo6/E8M7Up9lOtcxwTssx3ATwMbjvHQDqEDcBoA5xEwDqEDcBoA5xEwDqEDcBoA5xEwDq/A9Ggsti0lpFfgAAAABJRU5ErkJggg==" alt="" />

  这样我能得到独立的对象了。

  最后,在来讲讲切片中的步进,先看代码:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALUAAAAsCAIAAACsWG51AAACFElEQVR4nO2b0ZLDIAhF/ev9/OxDu9k2Cl5EomTumX3opBSJ3kUwbTkslPL+617cllzRLofzRDQS66M8Iglsfhfv4H5aUeIX76eeVnCiyx8TLcEAyjf4BxfyH1kuiVzmFF9yycOwJW4mGeTQx5FHIs0JnauPAc/D+jAFczPXsOZKBEnRpQJxC160OhmzfBmY9pfhYG7GpQZdInFbrF8fpmIF9GbKH/X+iMRzP7H54wBSyP35Y26mOd/1CDSHPiLEcXkxBY8+BiIx7Y+gn3z6iBPHEXD/3S28u81/atdjKX0E9Nm8l32IPf+wbhwmz82BFBslHikhIT4lY7/PHdg3si54Mvf42cdyCVsHR5ZDfRCNNfqIqEh2HjcvsfWpOKpcOQ57aNp0+wiiE9jfaqPKBTy4eF0zxSf1gRN7PiaO6tMHkmmojynEnq+DGd50cFRaDztMvS71geNSw/DzOU/+aOoDDAMcgpzE5o8DOzHE9XG+6ylTqA+c2PpDWk6PPj4BRwevk5rA/iVofwHNWJ9OYc3zOfD8Q0kAuEPcLanh+SnR4EwRDeqDaDTbv8jxKMhU1GVdZeFY0SL8nptkoaOPenUNrkv/NdmcS+PXspixnEwhSaE+iEa4Ppo7FPWRBeYPokF9EA1zf4t3NOxfHgDU3w7/9/P8Izvm81N/uUoSweUiGtQH0aA+iEbs98dIdgK/f0oewC9RHNr6s7X3agAAAABJRU5ErkJggg==" alt="" />

  所谓步进就是要走几步取一个,本来在没设置步进的时候,应该取到(1,2,3)的.

  而这里的步进表示走2步取一个。1->2第一步,2->3第二步,所以从1开始走2步就是3了。

  在不进行步进设置的时候默认为1,也就是每一个都取到。


3.加

  对序列进行加法运算,将返回一个新的对象。

a = ('scolia', 123, True)
b = ('good', 456)
c = a + b
print a
print b
print c

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbIAAABJCAIAAADXMzQlAAAJ/0lEQVR4nO2dy5XrKBCGCUshTCImDHcEw86rmQy0NXtHocUoAyehWUg8CgoEemC17/+de+7pdqOieJWKhykxAQAA8BAVacdX173GvTkOUtyF6PVeORzX17ANuhcH1MMheb1Vl6/MQa5XdUmaT1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A0AyYRQAAIMAsAgAAAWYRAAAIMIsAAED4H5dWq8me6JkmAAAAAElFTkSuQmCC" alt="" />

  并没有影响到原序列。

  那么不同类型的序列相加呢?

a = ('scolia', 123, True)
b = ['good', 456]
c = a + b
print a
print b
print c

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdUAAABSCAIAAACNGdl0AAAMY0lEQVR4nO2dO5LzOA7HeZs9wvJC5i22+wTDzNGEEypmsFUbONsTrGtqdIL1JTiB+H6IEPWg3d//V11dbrUIgKAIU5BNMA0AAGAEbLQBAADwi4L4CwAAY0D8BQCAMSD+AgDAGBB/AQBgDIi/AAAwhp8Rf+fHTb5GG/FrgyEAYDNnx181MfbFxHNjs6fY0Oop+GPebNkP4yX5d+zq/AilVT+zvAu1XwwAvw4m/j4F+2bm5+vgWaSmnulNboVp78mdRnFj3wAVwBshAJsw8fchlZuHT3nsjeS58fcp2HRE+H1JeUgMGqr90vhbsFmJo9+8AfjJ2PWv0n4eKnVoJDo1/h61djtsDThU+5Xxt9gqOTjWqwC8O2H+N5gtSpi04CzvQX5wSRd+s2DJOct7krUwTdytqJqYmAT7ZuwuzSGCHLsYbySCvc0vyb8Yv3P2xW8T97oye3yy5YvLl+2sOVLUVfFGLrnlDZMNf0juvdHUXpFc8OFB8TeXTPYYAi4AG6jEX/OnnW/pCe7F/ODLLA2P2Fhj2qppmcmzvPsjTTku/q7P59BmNTH+mN3v2J6C9pqcmqLEG3lPqd64yzmzfF171T8tOR3xd13FumTEXwA2sB5/s7lkFz5f1ZmppnRlVJrGZDl+GVsheOazCAl/V7SbdWj4sIgSf+k93eiNHu25D2sGbM8/lCUTPIZnoQBsYVP8tUdmeU/Xre5pjFvxaT3PdsVXWYGuyTHnvOSt8UhdCRuji/G3sP59ROfHXavmvnNv5D0leqMef6vaq/4JfFg0csf610umeuwl+SHPQgH4RXDxd37wcoIvWoEumVB+m3h6ZpJvDTO5D6kW4X5ytuQsCcdJLVndRgRZlsBL1nISwv02JqVZWtP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z/4imaeS4QEXsMhBx+/Xz0V8jGGo+5/BbU4q+aond4re3adkcpzJ9NwWMgBNfP+4CxeBPw/WMAABgD4i8AAIwB8RcAAMaA+AsAAGNA/AUAgDEg/gIAwBj+BoYuWcLaOi5ZAAAAAElFTkSuQmCC" alt="" />

  不行。

  列表的相加也是一样的,这里不重复举例。

  另外,和字符串的+号拼接也是一样的。


4.乘

  乘法和加法类似,只是几个一样的序列相加而已,这点和数学的乘法一样。

a = ('scolia', 123, True)
b = a*2
print a
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAccAAAA8CAIAAACcvOaLAAAIDUlEQVR4nO2dQZarKhCGWRZLeBsJyzAruMwyem8HTpt5VuHEHWQTvoGgFBSIisb2/t/p0yedxqIooCxKEsQAAACgHuLbCgAAwK1Y41X7t5Tvfm+NnRKNEK3ZK4fj+hqeg2lFBTtUqeujZd6YnVo2dUmZb1Bq5+ojqqpBjhstZ47DKzF51XH0P4V4CtUlCn+0fGnPSEa5S8RTrejkTWOif0vR0Lo8nW3nhRpu5WrTuKR3SGFlbO8oM/T6VXbhRsVcd6SMljfmRz8WJ15JmfPx275I3RH10bKWtFWtuIjkq2O9aq9fUn+GYRiGTqVvL16xwRYex0r/ltlB0+u3998NI8ybV6Z1t/1OO52NExdpWMpuDQ+ksHcsc4AwteKw5vjBSP+Wgp1FJxmT9uCxVw3D2kDs+yOKbyltRU0bHif58liv6od4XkuioRAusQu9aiBnwwjzLwkvJ6bfmATYr+FxfEp7xxaOg8eDmkODEdMK1SomIj7HmNtq2azb2kDs6yNqcbSkylxN8i/AetVy7Y0KjOWvyu2fyowR5VOI9se+GH/mSa71S4jnHFfaBf7oPmweKiwzFoziZU0L+Boa1QjRKtU4OWdoSGCueumeJtpImZg1Y4sECIxXnZM2NMa0tTubGPtm+qqwrtHsdGU6SpMvKdp/9UuIl5SNkO1DNtZiU3WzwpFVwzKcPrQHfxKtsJmQKYPE9HuRNWjbOyUapVohnkq16T7tFBmH0chM1RWP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/Ir2Wt7xfAACGYQi96jzhey0rerXYh+ZDtl21G+XV5Zz67NeNEsE7RTKF2HBZUtpd7xgAAOpVD1t1n7Wct87P+3Krxxx5C6F+fIfWa1mqVa+1mVph9G6XeNf0BgCAetXj5vqZXsSvK/V6rVLGGO8CY3a3BW4VgNuyzqvOC2ES8YUBoiQlIslhRMmL2QrfCppTMGpLTZ7kqQlWb2U8oUQ6Y42kkgCAG7DKq3LpUbuKnv7l3BdxY/GFwTvTn/vdDSOBT9OurirWOfCWcSummoNUKrwqALclyKsuPkUZgzRvn0DSXWZX3+x6vM7DoFCyUWGgmNRhneSStvtPuegzNDhVAG4K3QOw4Fan5zR+LDa90hVi1dwTpEInSIr57qvXmjytmt3tFsm5Rhklwlh1GPp+PnoKThWA+5LZrxoTb1Oao7H5MppJ9K7xnFgcv9kg+PGQURKyRDWqjJNMNkQJtxZn2rC808m1IxRClHVZVjVnVtm8M3wqAPcl89mqS1F3/+w5khPVXdG8AIBq4HsAAACgJvCqAABQE3hVAACoCbwqAADUBF4VAABqAq8KAAA1gVcFAICawKsCAEBNcMLKBYHljwCfvwAngRNWLggsfwz4rDA4BZywUijT+z6BY2cmLB/IrGn5+94xwIXACSsl1D5h5Txg+UhPhKvgYHDCSpHM2iesnAYsn1ESgEPACSubJO89YWU1sDzOtgG/BZywslnynhNW1gLL42wb8GvACSubJe84YWULsHzm8mLLYxsAOB6csLJRcq5RJnPCyrZYCZbfb/lQKwAOAieslEmudsLKtlQALI+zbcCvASesnHnCysmnuVThHpYfrjqwwQ3B9wAAAEBN4FUBAKAm8KoAAFATeFUAAKgJvCoAANQEXhUAAGoCrwoAADWBVwUAgJrAqwIAQE3gVQEAoCb/A0jObzbdiDWaAAAAAElFTkSuQmCC" alt="" />

  同样不影响原序列


5.成员检查

  这里主要是 in 和 not in 运算符的使用。

b = 3000
print id(b)
a = ('scolia', 3000, True)
print b in a
print id(a[1]), id(b)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcMAAAB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HU5EmppR7PH02erwIA+BJ4Mh8AoBWUFACgFZQUAKAVlBQAoBWUFACgFZQUAKAVlBQAoBWUFACgFZQUAKAVlBQAoBWUFACgFX9XveJOUAAAUMEpqdZud1G3DykAAKzh+aRmdPvdGYNTCgCwkShOGm68PK3z5y3w5g3xoz/Gcdkjj73wAOCglJV0/jdSSH+T5mWvUfu+ZrQUAA7JqpKWXjoS7HvPjSoAODLPKmnw3hDriw4DPikAHBBfScO3hni+pr9qt1FT5SKlybtEAAAOBU/mAwC0gpICALSCkgIAtIKSAgC0gpICALSCkgIAtIKSAgC0gpICALSCkgIAtIKSAgC0gpICALSSKqm/XZ73PhKp/yQp0dfzo/1Kow1LjfK+lu9Kig/a8PX9/VsIAMciVlJvC+fBmGhrpzTF25N00FIoM46DlrPQLB8um0aPYdZxUcVBn2w5bpepPPu3EACORqikRgml1AM6FR1rgk32gr2f/Q364r+vxU+ztezbQgA4Hr6STrLitnDWp5Ndz87r5CTFHuj8uZoepR7foGXk3/k6l7B/CwHgiPhvaY42w/feMGrUpEtpyugdb9/wtKpTLnYpTyfppddFav8WAsAxcUrqv+4+ualSeQ1JkHLdtHbOF5NKX5J15xYCwEGp3Lv3VMYoIfWfDSlD9n5OUGxYhbfvvre01tUo5P4tBIBjESqpe9BnWiovXqAVnFpKEGQMApXJc0jJ+0pCf7Pi+O3fQgA4HjyZDwDQCkoKANAKSgoA0Mp/7ZurDjLMHAkAAAAASUVORK5CYII=" alt="" />

  这里的结果很奇怪,如果还记得python中的缓存池(上篇有说过)的话,不是说数字只在 -5~257 才会有缓存行为吗?看来python内部针对这种情况特别做了优化,达到了节省内存的效果。

  就算赋值行为在下面也一样。

a = ('scolia', 3000, True)
b = 3000
print b in a
print id(a[1]), id(b)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAboAAAA4CAIAAAAEmqq1AAAHXUlEQVR4nO2dy5XzKBCFCYsQJhEThhzBsPNqJgNtm72j0OJXBk6CWQgEBYVUtiXZrbnf6dOn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JbZ6nJvXE9JSln58c5eLppsa+sjiZYE/hILAQDnpPjiXOY16Sm4lxSCilE8LSZhvLD0vZJxZ1wfmVhWou+3EABwVohc5l8zrpS6/KQQX3srWntq5VaXSsvCt1kUulTjvt5CAMBpWbkyntSh6btlVz1Gq/kLKZkkOaO0/VMdGfOzvB+tXYwMfr+FAICzUcllulemuHcmv7hMb6YpT8kO5YqjWvlU33TBRAt/lYUAgDOC29QBAEAE5BIAAERALgEAQATkEgAAREAuAQBABOQSAABE/AczWHP0mTHLbgAAAABJRU5ErkJggg==" alt="" />

  看来在变量赋值时还有隐藏行为,python会检查元祖和列表中是否已经有一样的对象了,若有则赋值时不重新创建,而是重复引用。


6.元素长度计算

  其实是 len() 内置函数的调用,该函数会返回容器中元素的数量。

a = ('scolia', 3000, True)
print len(a)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbAAAAAeCAIAAADCTdxXAAAFeklEQVR4nO2czXXsKgzHKYsSXiOhDE8Fj51X93XANuynCm/cwTTBWxhsBOJjPLYzufP/nXtybiZ8CEkIITsRDgAAgHPOObGz33yX8j6/OvukxCCEsa+Ow/H+El6DNeIAPRwy10PLujIn1VZ1T5ufoFfPh3vUoQo5z1uu9MMXYAPi4rg3IW5CTYWODy1HHa3PqtBF3NQT9tllzvkuxUDnimT2ek8l3Mu77cAe65DGynrrKOtmPfZ13ClYMEdJaXVlPvRXc8/0tLmeeO1NjvWoh5ZHjfbUKt5k5INhAuKsR6kfzjnnJlUO6lEz5xsvZp7vsmrvWd+jn+5wjmhLWBMO20kHmW0YLpOwl5clPJFO63i2Y3ldxWnLiVOA+S4FuwEuUia14Lm9nHs2/fl5j+JXSldxpA7PG/lomIAYJ1aREJkV0ztpZ0BMxtnhHHGXtDvR2s5b8+sSnsej1zq+cZ6ynbQcmgJYI5RRTB56jTL3zbJbtmfTnx/3qKa3lNq828jHwwTE/omtStYZX2P9t8ouedxNCPPt/7P82/an1qMQty2b8zfiZef7mkvaZmmYZamaNogltGo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X89Ru/u8gAgAAL8MBEQAAPAgIAIAgAcBEQAAPAiIAADgQUAEAAAPAiIAAHgQEAEAwIOACAAAHi4gWiUC+C0OAMDnwP09RBl+F2jWEiERAPAxVK/MViEeAgA+h1JAtAoXZgDAh4EMEQAAPPWnzIiIAIAPovpQxSoh8cfWAACfQv21G6SHAIAPAi9mAwCA538mZTh9nMooDAAAAABJRU5ErkJggg==" alt="" />

  计算是从1开始的,和索引不同,要注意区分。

  还有,虽然这里是写在序列之中,但是这个方法对字典也适用,而字典算是特殊的一种'序列'。

a = {'a':1,'b':2}
print len(a)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAckAAAAeCAIAAADIEXIFAAAFjklEQVR4nO2dQZbbIAyGORZH6EXCMZwTlJ1X7Q3YDvucwhvfIJegC4ONQGCcwU7a/t/rm9fJYCEkIQvFmREOAABAb0Q3SfNDysf8XSmTEoMQxvbQKOXzNbwGa0QHO3SZ66ll3ZiT2jd1y5h30Grn7hHV1SDnRcuVcfgOGnPrsgfuQtyFmspjRh2ZyqpwibirA65+KTLmhxQDnSvS2bsw1fBVPm0zt3iHDFbWe0dZN+ux7cIXFQvuKBmtbsynvu1uv5Yx1xOvfZe+EfXUspe0Q6v4EMmfQlNunfUo9dM559ykyreaaJjzg5eImR+yGjqzfkQ/fSHOot1lTSgBJh10tkFcpmEr39bwRBq949mKhXUVpy0nLkzmhxTsXrrImNSD517l3NGi7P0Rxa+UrqKnDc+T/DE05da43IvWkwVEeuhuzK2JnBfiLL4kvZw44MW2wPc1PI9nq3f84LyQPGk5tDCxRiijmOr4GmO+NsvLuh0tyt4eUbvRUhrzaZI/iKbc2r4GqxKTxed0/62yS3V5F8J8+f8s/7atrvUoxH2rMf2Rf0kivj+VjlkGZrWzpgNiDa0ahDBKDUHOFRoSmKtGPdMGHBmTcyTCSLHA5NatjUPrTT97sIn1L5avSudazE7Pqos0OUphfulRiFHKQUhzk4O32DrdpnBm1XQMpw/14FdhFb43svaUGL83WYOufVJiU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IBdGn83dvSrfpFbAQBgj2P91llLid8DAQAAexzIrUisAADQSGtutUogsQIAQCONf9NFRn8xRaPfCgAAdRrfy4pA+QoAAHvgswMAANCfPxgs9x1OYVlAAAAAAElFTkSuQmCC" alt="" />


7.取序列中的最大、最小值

  这里其实是内置函数 max() 和  max() 的使用,其会返回序列中的最大、最小值。

  关于不同数据的比较请参照:戳这里

  或者参考我之前关于python的数字的博文。

a = ('scolia', 3000, True)
print max(a)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbcAAAAoCAIAAADysiOeAAAGD0lEQVR4nO2cwZnjLAyGKYsS/kZCGU4Fyy2X3b8DX4d7qvDFHaQJ78GAkRCYOLYnmf3eZ5/ZiYOFEEIIxRn1GwAAQBk1AQAAKIMoCQAANRAlAQCgxvNRcrxrfR9f7XcwqlOqd6/KkXh/Dc/B9WoHO+zS18PqujEHs27qljbfQaudd/eoXQ1ynLec6YfHwKLk7M1Xpa7KDIVbHlbfbDJoZ8It6mqemLRNczzetepoX4nOfjK4hlt5t2XZMjuksXF+doybRntru3GjYmE6SkarG/NhL6sLqaXN+aRjX2Vfj3pYvZe0p0bxJpLPg0TJ0d60fUzTNE2DKYf/pNnkG89zP9511QlGe0/e3eAxyTpxfdiWBxt0dkFcpmErL2t4II2z41k28DiKw4aTJgvjXStxVZxkTDqDx941Tc8mSt/vUfJI6Sj2tOFxkk+ERMk0BUs0y6aWH2kboySTs8Fj0lv47cSUGw/dr2t4HI/W2fGN8+TuoOHQZMH1yvRGyFjPMea2Xjbr9myi9O0eteotpTbvJvlUSJRs18YZNvj0FOxfGjdnfFel+i//y/xvWbTW3pS6LnmfP1DP4cDXcXibuWGWz1raINXQmU6p3pguyDlDQ4Jw182OtFBF2uQ84ytkAxei5FIkoTmg7z3YxPmL5bt4X7PZ6UlwlqZvWvV/7E2pm9ad0v1Fd95isbtF4cyqvI2kD53Br8IofOUhVmyEeW+yBh37YFRnTK/U1Zi+PKeDIX6YeWapr9w3coPkbWJ5at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sqEmLiUdJL4X+7cFMDAAAvD8sSkrlRT1fim+NVms7Lv8XbmRX4ktknQCATyI/cc95YIx/lfCXvrUaJdM0FVESAPAx8FzS+uiYZo7xN7tDLrnIAwCAD4BFyVg8VCRNpIVKVpdM7gmXlrQxiYg+Sb1cNC1pAgDAG4Pv3gAAQA1ESQAAqIEoCQAANRAlAQCgBqIkAADUQJQEAIAaiJIAAFADURIAAGr8BUfGR65RjC2tAAAAAElFTkSuQmCC" alt="" />


  关于序列的内容暂时写这么多,以后有需要的话会继续补充。

上一篇:DRF框架之 serializers 序列化组件


下一篇:fastJson注解@JSONField使用的一个实例