s = "Alex SB 哈哈\r\nx:1\r\ny:2\r\nz:3\r\n\r\n自行车"
["Alex SB 哈哈\r\nx:1\r\ny:2\r\nz:3", "自行车"]
?ret = s.split('\r\n\r\n')
print(ret)
ret = s.strip().split('\r\n')
res = ret[0] # Alex SB 哈哈
print(res.split(' ')) # ['Alex', 'SB', '哈哈']
print(res.split(' ')[1])
list1 = [
("Alex", "烫头"),
("Egon", "街舞"),
("Yuan", "喝茶"),
("Ya", "睡觉"),
]
name = input('请输入姓名 ').strip().title()
for i in list1:
if i[0] == name:
print("%(name)s's hobby is %(hobby)s" %({'name':name, 'hobby':i[1]}))
break
else:
print('查无此人')
我有一个HTML文件"login.html"
f = open('login.html', mode='r', encoding='utf-8')
html_s = f.read()
print(html_s)
f.close()
f = open('login.html', mode='rb')
html_s = f.read()
print(html_s)
f.close()
"Alex 花了一百万买了辆电动车,真SB。"
s2 = "Alex 花了一百万买了辆电动车,真@@xx@@。"
ret = s2.replace('@@xx@@', 'SB')
print(ret)
from itertools import permutations
ret = permutations('1234', 3)
print(list(ret))
list1 = [11, 22, 33]
list2 = ['aa', 'bb', 'cc']
from itertools import chain
list1 = [11, 22, 33]
list2 = ['aa', 'bb', 'cc']
for i in chain(list1, list2):
print(i)
原文:https://www.cnblogs.com/cjwnb/p/11715587.html