列表


In [ ]:
aList = [1, 2, 3, 4, 5, 6]
aList

In [ ]:
type(aList)

In [ ]:
aList = [1, 2.0, "python"]
aList

In [ ]:
list("python")

In [ ]:
print aList[0]
print aList[2]
print aList[1:]
print aList[-1]

In [ ]:
len(aList)

In [ ]:
aList[1] = 7.0
aList

In [ ]:
print [1, 2, 3] > [3, 4, 5]
print ["a", 2] == ['a', 2]

In [ ]:
print 1 in aList
print 2.0 in aList
print 2.0 not in aList

In [ ]:
aList += [3, 5, "cool"]
aList

In [ ]:
print max(aList)
print min(aList)

In [ ]:
sorted(aList)

In [ ]:
sorted(["c", "g", "w", "a", "L"])

In [ ]:
rList = reversed(aList)
for i in rList:
    print i

In [ ]:
for i, v in enumerate(aList):
    print i, v

In [ ]:
sum([1, 2, 3, 4, 5])

In [ ]:
aList.append(9)
aList

In [ ]:
aList.extend(['1', 90, "a"])
aList

In [ ]:
aList.insert(0, 7777)
aList

In [ ]:
aList.pop()
print aList
aList.pop(0)
aList

In [ ]:
aList.remove(9)
aList

In [ ]:
aList.reverse()
aList

In [ ]:
aList.sort()
aList

In [ ]:
aList.append([5, "c", 90])
aList

元组


In [ ]:
aTuple = (1, 2, "python")
aTuple

In [ ]:
type(aTuple)

In [ ]:
tempTuple = tuple("python")
tempTuple

In [ ]:
print aTuple[0]
print aTuple[2]
print aTuple[1:]
print aTuple[-1]

In [ ]:
len(aTuple)

In [ ]:
aTuple[1] = 7.0

In [ ]:
aTuple = aTuple[2], aTuple[0], aTuple[1]
aTuple

In [ ]:
aTuple = aTuple + (9, "cool")
aTuple

In [ ]:
print (1, 2, 3) > (3, 4, 5)
print ("a", 2) == ('a', 2)

In [ ]:
print 1 in aTuple
print 2.0 in aTuple
print 2.0 not in aTuple

In [ ]:
print max(aTuple)
print min(aTuple)

In [ ]:
sorted(aTuple)

In [ ]:
rList = reversed(aTuple)
for i in rList:
    print i

In [ ]:
for i, v in enumerate(aTuple):
    print i, v

In [ ]:
sum((1, 2, 3, 4, 5))

In [ ]:
# --------------------------------------------------------------------------------  
# Copyright (c) 2013 Mack Stone. All rights reserved.  
#   
# Permission is hereby granted, free of charge, to any person obtaining a copy  
# of this software and associated documentation files (the "Software"), to deal  
# in the Software without restriction, including without limitation the rights  
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
# copies of the Software, and to permit persons to whom the Software is  
# furnished to do so, subject to the following conditions:  
#   
# The above copyright notice and this permission notice shall be included in  
# all copies or substantial portions of the Software.  
#   
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  
# THE SOFTWARE.  
# --------------------------------------------------------------------------------