List

1# range()method: range(a1,a2,b):from a1 to a2,including a1,not a2,with b as the interval;

                               range(a): from 0 to a,successive integer,contains a numbers;

     [a1:a2:b]:from a1 to a2,including a1,not a2,with b as the interval;

     random(a1,a2):a random number between a1 and a2,including a1 and a2.

2#Notice that the code is spam.append('cat') and spam.insert(1,'chicken'),not spam=spam.append('cat') and spam=spam.insert(1,'chicken').Neither append() nor insert() gives the new value of spam as its return value.(In fact ,the return value of append() and insert() is None,so you definitely won't store this as the new variable value.

3#The del statement is good to use when you know the index of the list you want to deleate;The remove is good to use when you know the value of the list you don't want.

4# The differences between Function and Method:

  Funciton-a series of statements which returns some value to the caller.It can be passes zero or more arguments which can be used in the execution of the body.

  Method-a funciton which is defined inside a class body.If called as an attribute of an instance of that class,the method will get the instance object as its first argument(which is usually called self)

5#Reference_

spam=[1,2,3,4]
cheese=spam
cheese[1]='hello'
print(cheese)
print(spam)

when you creat the list of spam,you assgin a reference to it in the spam variable,the next copies only the list reference in spam to cheese,not the list value itself.

posted on 2017-08-17 23:27  auleon  阅读(133)  评论(0编辑  收藏  举报