Python
不用规定变量类型
幸运数=588
x,y=y,x
alt+p
print(r"D:\three\two\one")
""" """
'520'+'1314'
print('你好\n'*3)
ctrl+c暂停
import random
random.randint(1,100)
import decimal
a=decimal.Decimal('0.1')
x=1+2j
x.real
x.imag
int()
x**y
3//2=1
divmod(5,2)=(2,1)
not
and
or
if score>=100:
print('nihao')
elif score>=80:
print('nihao')
else: print('nihao')
print()
end=' '
for each in ' FishC'
print(each)
len('FISHC')
'FISHC'[i]
for i in range(0,101,1)
for/while
else:
arr[-1]
arr[1:3]
arr[::2]
heros.append('白龙马')
heros.extend(['大大怪','小小怪'])
heros.insert(0,'唐长老')
heros.remove('大大怪将军')
heros.pop(0)定角标清除
heros.clear()
heros[6:]=['海绵宝宝','派大星']
arr.sort()冒泡从小到大
arr.reverse()数组倒置
arr.count(9)
arr.index(3)
heros[heros.index('白龙马')]='草泥马'
goxiong=heros.copy()
p=[1,2,3,4]
j=[5,6,7,8]
pj=p+j
pj=pj*3
for i in brr:
for each in i:
print(each,end=' ')
print()
x=[1,2]
y=x.copy()
z=x
import copy
y=copy.copy(x)地址传递
y=copy.deepcopy(x)值传递
x=[2,4,6,1]
y=[3*i*i for i in x]列表推导式
code=[ord(i) for i in 'fishC']
x=[i for i in range(10) if i%2==0]
flatten=[col for row in x for col in row]
str='123321'
str[::-1]
x=x.capitalize()整个字符串第一个字母大写
x=x.lower() 所有小写
x=x.upper()所有大写
x=x.title() 单词第一个字母大写
x=x.center(15,'*')居中对齐
x=x.ljust(10)
x=x.rjust(10)
x=x.zfill(6)
x.find('春')
x.rfind('春')
x.replace('建设','消灭')
table=str.maketrans('abcdefg','1234567')转换标准
'i love apple and banana'.translate(table)
x='我爱python'
x.startswith('我')
x.endswith('python')
x.istitle()
x.isupper()
x.islower()
x.isalpha()
x.isspace()空格字符串
x.isprintable()能否全打印
x.isalnum()
x.isidentifier()
' 左侧不要留白'.lstrip()
'右侧不要留白 '.rstrip()
x.split(',')
x.splitlines()
'.'join(['www','shidacheng','3vdo','com'])
'1+1={},2+2={}'.format(2,4)
'{1}见到{0}就很激动'.format('小狗','火腿肠')
dict1={'name':'tom','sex'='男','age'=18}
dict1['name']='baga'
del(dict1)
del(dict1['name'])
dict1.clear()
print(dict1.keys())是个列表可以遍历
print(dict1.values())
print(dict1.items())
dict1.get('name',-1)
for key,value in dict1.items():
print(key,'=',value)
A={1,2,3,1}集合不重复
print(type(A))
A=set('apple')
A.add(100)增一个
A.update([9,8,7,6])增加一堆
A.discard(100)
A.pop()随机删除
10 in A
10 not in A
len(x)
del()
max(x)
min(x)
sum(x)
sorted(x)
list1=list(reversed(list1))
range(start,end,step)
字符串 列表 元组 字典 集合
for i in enumerate(list1):
print(i)
tuple() 转元组
list() 转列表
set() 转集合
str()转字符串