Our main discussion is the list and tuple of 2 sequences.
(1) Index
0 points to the first character, 1 points to the last character.
Example:
months = [ ' January ', ' February ', ' March ', ' April ', ' may ', ' June ', ' July ', ' August ', ' September ', ' October ', ' November ', ' December ',]ending = [' st ', ' nd ', ' rd '] + 17 * [' th '] \ + [' st ', ' nd ', ' rd '] + 7 * [' th '] \ + [' st ']year = raw_input ("Years:") Month = raw_input ("Month (1-12):") Day = raw_input ("Day (1-31):") month_number = int (month) day_number = int (day) month_name = months[month_number - 1] ordinal = day + ending[day_number - 1]print month_name + ' ' + ordinal +&nbSP; ', ' + year
(2) sharding
A range of elements can be accessed through a shard operation, and The Shard is implemented by an index separated by 2 colons. The left side must be greater than the right and does not contain the right. You can specify a step by the third value.
Example:
Print "url example ' http://www.baidu.com '" url = raw_input (' Please enter the URL: ') domain = url[11:-4]print "domain name:" + Domain
(3) Sequence addition
>>>[1,2,3] + [4,5,6]
>>> ' Hello ' + ' world '
Note that lists and characters cannot be added.
(4) multiplication
>>> ' python ' * 5
(5) Membership
Use the in operator to detect whether a member is in a sequence.
Example:
Database = [[' Albert ', ' 1234 '], [' Dilbert ', ' 4242 '], [' Smith ', ' 7524 '], [' Jones ', ' 9843 '], [' Buranle ', ' 8888 '] Username = raw_input ("username:") pin = raw_input ("PIN Code:") if [Username,pin] in Database:print "Access granted"
(6) Length, Min and Max values
The built-in functions Len, Min, and Max.
This article from "Otherwise" blog, please be sure to keep this source http://buranle.blog.51cto.com/8870751/1641693
Python sequence operations