python数据处理常用方法(二)

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

文章链接: https://www.mfisp.com/19227.html

文章标题:python数据处理常用方法(二)

文章版权:梦飞科技所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    建站教程

    python数据处理常用方法

    2023-4-3 11:24:29

    建站教程

    python数据处理常用方法(三)

    2023-4-4 10:04:19

    0 条回复 A文章作者 M管理员
    如果喜欢,请评论一下~
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索

    梦飞科技 - 最新云主机促销服务器租用优惠

    可以介绍下你们的服务器产品么

    云服务器你们是怎么收费的呢

    租用vps现在有优惠活动吗