import random
listC = ['加多宝', '雪碧', '可乐', '勇闯天涯', '椰子汁']
print(random.choices(listC), type(random.choices(listC))) # choices函数返回列表类型数据
print(random.choice(listC), type(random.choice(listC))) # choice函数返回字符串类
listA = ['水煮干丝', '豆腐', '基围虾', '青菜', '西红柿炒鸡蛋']
listA.append('红烧肉')
print(listA)
listA.remove('水煮干丝')
print(listA)
dictMenu = {'卡布奇诺': 32, '摩卡': 30, '抹茶蛋糕': 28, '布朗尼': 26}
Sum = 0
for i in dictMenu.values():
Sum += i
print(Sum)
s = input()
print(eval(s[::-1])) # eval函数会根据输入的内容字符串s中内容转换为相应的类型
print('{:+>25}'.format(123456))
print('{:>30,}'.format(12345678.9))
print('0x{0:x},0o{0:o},{0},0b{0:b}'.format(0x1010))
s = input()
print(s.lower())
s = input()
print(s.count('a'))
s = input()
print(s.replace('py', 'Python'))
data = input()
a = data.split(',') # a是列表类型
b = []
for i in a:
b.append(i)
print(max(b))
s = '9e10'
if type(eval(s) == type(0.0)):
print('True')
else:
print('False')
s = '9e10'
print('True' if type(eval(s)) == type(0.0) else 'False')
s = '123'
print('True' if type(eval(s)) == type(1) else 'False')
ls = [123, '456', 789, '123', 456, '798']
Sum = 0
for item in ls:
if type(item) == type(123):
Sum += item
print(Sum)
while True:
s = input()
if s in ['y', 'Y']:
break
while True:
s = input()
if s== 'y' or s== 'Y':
exit()
try:
a = eval(input())
print(100 / a, type(100 / a)) # float
except:
pass
def psum(a, b):
return a ** 2 + b ** 2
if __name__ == '__main__':
t1 = psum(2, 2)
print(t1)
def psum(a, b=10):
return (a ** 2 + b ** 2), a + b
if __name__ == '__main__':
t1, t2 = psum(2)
print(t1, t2)
def psum(a, b):
return (a ** 2 + b ** 2), a + b
if __name__ == '__main__':
t1, t2 = psum(2, 2)
print(t1, t2)
n = 2
def psum(a, b):
global n
return (a ** 2 + b ** 2) * n
if __name__ == '__main__':
print(psum(2, 3))
pyinstaller -F py.py
pyinstaller -I py.ico -F py.py
import jieba
txt = '中华人民共和国教育部考试中心'
ls = jieba.lcut(txt, cut_all=True)
print(ls)
[‘中华’, ‘中华人民’, ‘中华人民共和国’, ‘中华人民共和国教育部’, ‘华人’, ‘人民’, ‘人民共和国’, ‘共和’, ‘共和国’, ‘国教’, ‘教育’, ‘教育部’, ‘教育部考试中心’, ‘考试’, ‘中心’]
try:
f = open('a.txt', 'x')
except:
print('文件存在,请小心读取!')
ls = [123, '456', 789, '123', 456, '789']
ls.insert(3, '012')
print(ls)
[123, ‘456’, 789, ‘012’, ‘123’, 456, ‘789’]
ls = [123, '456', 789, '123', 456, '789']
ls.remove(789)
print(ls)
ls = [123, '456', 789, '123', 456, '789']
print(ls[::-1])
[‘789’, 456, ‘123’, 789, ‘456’, 123]
ls = [123, '456', 789, '123', 456, '789']
print(ls.index(789))
d = {123: '123', 456: '456', 789: '789'}
print(list(d.values()))
d = {123: '123', 456: '456', 789: '789'}
print(list(d.keys()))
PS:我的站点:https://www.blueflags.cn