栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 判断字符串是否存在另一个字符串中

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 判断字符串是否存在另一个字符串中

前言

有很多的场景都要用到在一个文本中匹配字符串的需求

目录标题
  • 前言
  • 一.in操作符
  • 二.正则判断
  • 总结:

一.in操作符
# 字典
dicc = {'host':'1.1.1.1'}
print('host' in dicc)  #True
print('host' in dicc.keys()) #True

# 列表
japan_is_shit = ['host','ip','port']
print('host' in japan_is_shit)  #True

# 字符串
japan_is_shit = 'japan_is_shit_host'
print('host' in japan_is_shit)  #True

# 元组
japan_is_shit = tuple(['host','ip','port'])
print('host' in japan_is_shit)  #True

二.正则判断

正则判断思路:完全匹配,根据返回结果来判断,这里用re.findall()来试。

res = re.findall('host','japan_is_shit_host')
if len(res) > 0:
    print('匹配成功')
总结:

以后见到的匹配方式仍会添加。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1009832.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号