# python数据处理常用方法（二）

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/19227.html | 发布：2023-04-03 | 更新：2023-04-03 | 分类：建站教程

## 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 {d}.")

 

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

 

``

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
