6、正則取出固定位置的字符
template = "DF','17340','http://www.zgglkx.com','2021','205')"
res = re.findall(r"DF','(.*?)',",template)[0]
print(res)
結果:
17340
Process finished with exit code 0
7、正則匹配判斷字符串中是否含有中文
import re
Pattern = re.compile(u'[\u4e00-\u9fa5]+')
key='[25] 張初兵,榮喜民.仿射利率模型下確定繳費型養老金的最優投資[J]. 系統工程理論與實踐,2012,32(5):1048-1056. Zhang Chubing, Rong Ximin. Optimal investment for DC pension under the affineinterest rate model[J]. Systems Engineering-Theory & Practice, 2012, 32(5):1048-1056.'
match = Pattern.search(key)
if match:
? ? print("存在中文")
8、list添加刪除連接元素
在最后添加元素
list.append()
? ? 1
從最后刪除元素
a = list.pop()
? ? 1
用#連接列表的元素
'#'.join(list[3:5])
? ? 1
9、函數變量聲明
def sum(*args):
? ? a,b,c=args
? ? d = a+b+c
? ? print({f"The sum is fv7fbbx.")
? ? 1
? ? 2
? ? 3
? ? 4
輸入:
sum(1,2,3)
? ? 1
輸出:
The sum is 6.
10、input對話框獲取實時輸入
age = input("how old qre you: ")
print("I am ",age,"years old")
how old are you: 2
I am ?2 years old
Process finished with exit code 0