python 列表,集合,字典,字符串的使用

PY

PY基础

append 在末尾添加元素
pop 删除末尾元素
insert(i,item)在i位插入元素
pop(i)删除i位元素
只有1个元素的tuple定义时必须加一个逗号,,来消除歧义
if
elif
else
s =int(input('please input a num'))
print s
range(1,5)左闭右开
range(10)1到9
//使用字典

d = {'Michael': 95, 'Bob': 75, 'Tracy': 85}
d['Michael']
95
‘Michael’ in d可以用来判断是否在里面
pop+first值可以从字典中删去

//使用集合

s = set([1, 1, 2, 2, 3, 3])
s
{1, 2, 3}
set 用add和remove来增删元素
s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
s1 & s2
{2, 3}
s1 | s2
{1, 2, 3, 4}
//
python 修改字符串
str='fuck you'
str=list(str)
print str
str[-3]='Y'
str=''.join(str)
print str

PY函数

max(2, 3, 1, -5)
3
python函数类似于js,是一种弱类型的,无需返回值
pass语句什么都不做,但是可以用作占位符
PYTHOn条件语句和函数后面要加冒号啊啊啊啊,怎么老是忘??

posted @ 2019-09-29 16:11  NTS100K  阅读(254)  评论(0编辑  收藏  举报
浏览器标题切换end