bbs.fish.com
>>> member = ['小甲鱼','小布丁','迷途','意境']
>>> member
['小甲鱼', '小布丁', '迷途', '意境']
>>> number = [1,2,3,4,5]
>>> number
[1, 2, 3, 4, 5]
>>> mix = [1,'小甲鱼','3.14']
>>> mix
[1, '小甲鱼', '3.14']
>>> empty = []
>>> empty
[]
>>> member.append('俘虏娃娃')
>>> member
['小甲鱼', '小布丁', '迷途', '意境', '俘虏娃娃']
>>> len(member)
5
>>> member.extend(['附录','crazy 迷恋'])
>>> member
['小甲鱼', '小布丁', '迷途', '意境', '俘虏娃娃', '附录', 'crazy 迷恋']
>>> member.insert(0,'牡丹')
>>> member
['牡丹', '小甲鱼', '小布丁', '迷途', '意境', '俘虏娃娃', '附录', 'crazy 迷恋']
>>> member[0]
'牡丹'
>>> member[1]
'小甲鱼'
>>> tmp=member[0]
>>> member[0]=member[1]
>>> member
['小甲鱼', '小甲鱼', '小布丁', '迷途', '意境', '俘虏娃娃', '附录', 'crazy 迷恋']
>>> member[1]=tmp
>>> member
['小甲鱼', '牡丹', '小布丁', '迷途', '意境', '俘虏娃娃', '附录', 'crazy 迷恋']
>>> member.remove('意境')
>>> del member[1]
>>> member
['小甲鱼', '小布丁',】
>>>del member
>>> member.pop()
'crazy 迷恋'
>>> name = member.pop()
>>> member
['小甲鱼', '小布丁', '迷途', '俘虏娃娃']
>>> member
['小甲鱼', '迷途', '俘虏娃娃']
>>> member[1:2] 分片 2不包含
['迷途']
>>> member[:2]
['小甲鱼', '迷途']
>>> member[0:]
['小甲鱼', '迷途', '俘虏娃娃']
>>> member[:]
['小甲鱼', '迷途', '俘虏娃娃'] //拷贝
>>> list1*=5
>>> list1
[434, 4324, 434, 4324, 434, 4324, 434, 4324, 434, 4324]
>>> 434 in list3
True
>>> 123 not in list3
True
>>> list4=[123,['小鱼','牡丹'],456]
SyntaxError: invalid character in identifier
>>> list4=[123,['小鱼','牡丹'],456]
>>> '小鱼' in list5[1]
Traceback (most recent call last):
File "<pyshell#88>", line 1, in <module>
'小鱼' in list5[1]
NameError: name 'list5' is not defined
>>> '小鱼' in list4[1]
True
>>> dir (list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> list3
[434, 4324, 434, 12312]
>>> list3.count(434)
2
>>> list3.index(434)
0
>>> list3.index(434,1,4) //查看位置
>>> list3.reverse()
>>> list3
[12312, 434, 4324, 434]
>>> list6=[3,2,5,1,6,3]
>>> list6.sort()
>>> list6
[1, 2, 3, 3, 5, 6]
>>> list6.reverse
<built-in method reverse of list object at 0x0000017747F9B9C8>
>>> list6.reverse()
>>> list6
[6, 5, 3, 3, 2, 1]
>> list6.reverse()
>>> list6
[1, 2, 3, 3, 5, 6]
>>> list6.sort(reverse=True)
>>> list6
[6, 5, 3, 3, 2, 1]
>>> tuple1[1]
2
>>> tuple1[4:]
(5, 6, 7, 8, 9)
>>> tuple2=tuple1[:]
>>> tuple2
(1, 2, 3, 4, 5, 6, 7, 8, 9)
>>> temp=(1,)
>>> type(temp)
<class 'tuple'>
>>> 8*(8)
64
>>> 8*(8,)
(8, 8, 8, 8, 8, 8, 8, 8)
>>> temp=()
>>> type(temp)
<class 'tuple'>
>>> temp = ('小甲鱼','黑夜','迷途','小布丁')
>>> temp = temp[:2]+('意境',)+temp[2:]
>>> temp
('小甲鱼', '黑夜', '意境', '迷途', '小布丁')
>>> del temp
>>> temp
temp = ('小甲鱼','黑夜','迷途','小布丁')
>>> str.capitalize()
'Xiaoxie'
>>> str1.casefold()
'dfdfdfd'
>>> str1.center(20)
' DFDFDFD '
>>> str1.count('F')
3
>>> str2='I \tlove\t.con'
>>> str2.expandtabs()
>>> str2.find('l')
3 //下标
>>> str2.index('g')
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
str2.index('g')
ValueError: substring not found //返回异常
>>> str2.isalpha()
False
>>>
>>> str2.isdecimal()
False
>>> isdigit()
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
isdigit()
NameError: name 'isdigit' is not defined
>>> str2.isdigit()
False
>>> str2.islower()
False
>>> str2.isspacce()
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
str2.isspacce()
AttributeError: 'str' object has no attribute 'isspacce'
>>> str2.istitle()
False
>> str2.isUpper()
>>> str2.join('12345')
'1I \tlove\t.con2I \tlove\t.con3I \tlove\t.con4I \tlove\t.con5'
>>> str6.replace('love','LVOE')
'i LVOE fosj '
>>> str6='i love fosj '
>>> str6.split()
['i', 'love', 'fosj']
>>> str6.startswith('i')
True
>>> str7=' sssss '
>>> str7.strip() //去掉左右的空格
'sssss'
>>> str7.swapcase()
' SSSSS ' //翻转大小写
>>> "{0} love {1}.{2}" .format("I","FINSHX","COM")
'I love FINSHX.COM'
>>> '{0:.1f}{1}'.format(27.658,'GB')
'27.7GB'
>>> '%c' % 97
'a'
>>> '%c %c %c' % (97,98,99)
'a b c'
>>> '%s' % 'i love finsh com'
'i love finsh com'
>>> '%d+%d=%d' % (4,5,4+5)
'4+5=9'
>>> a=[1,2,3,4,5,6,7]
>>> b=[3,4,5,6,8]
>>> list(zip((a,b))
Myfirst._doc_ //打印函数的文档
'这是函数的文档'
help(Myfirst)
'这是函数的文档'
def test(*params): //收集参数
print('参数长度是:',len(params));
print('第二个参数是:,'params[1];
>>> def back():
return 1,'xiaojiayu',3.24
>>> back()
(1, 'xiaojiayu', 3.24)