常用Python的BIF指令

来源:互联网 发布:淘宝快递盒上会有 编辑:程序博客网 时间:2024/05/22 16:48
>>> # 常用BIF
>>> # 内置函数多为紫色,字符串为绿色,关键字为橙色
>>> print('hello world')
hello world
>>> cast=['a','b','c','d']
>>> # append()在列表末尾增加一个数据项,pop()从列表末尾删除数据项,extend()可在列表末尾添加多个数据项,remove()移除列表中的指定项,insert()在指定的数据前增加一个数据项
>>> cast.append('e')
>>> print(cast)
['a', 'b', 'c', 'd', 'e']
>>> cast.pop()
'e'
>>> print(cast)

['a', 'b', 'c', 'd']

>>> cast.extend(['a','b'])
>>> print(cast)
['a', 'b', 'c', 'd', 'a', 'b']

>>> cast.remove('d')
>>> print(cast)
['a', 'b', 'c', 'a', 'b']
>>> cast.insert(0,'w')
>>> print(cast)
['w', 'a', 'b', 'c', 'a', 'b']

>>> for a in range(1,5):
             print(a,end='') 
1234

#其中a为目标标识符,每次运行时目标标识符会指示一个不同的数值

>>> number=[3,4,5]
>>> isinstance(number,list)
True
>>> isinstance(number[1],list)
False
>>> isinstance(number[1],int)
True

#使用find可以查找字符串中的子串,如果没有则返还-1,如果有则返回 该子串的位置

>>> each_line='i tell you that the man is not bad'
>>> each_line.find(':')
-1
>>> each_line='i tell you: that the man is not bad'
>>> each_line.find(':')
10

0 0
原创粉丝点击