当前位置: 首页 > news >正文

《python语言程序设计》2018版第8章第2题检查子串, 使用str类的find方法检查一个字符串是否是另一个字符串的子串

请添加图片描述

##代码一


def str_find():str1 = input("Enter no1 str: ")str2 = input("Enter no2 str: ")if str2 in str1:print("The str2 is in str1")else:print("The str2 is not in str1")str_find()

请添加图片描述

代码二

def str_find():str1 = input("Enter no1 str: ")str2 = input("Enter no2 str: ")if str1.find(str2) >= 0:print("The str2 is in str1")print(str1.find(str2))else:print("The str2 is not in str1")print(str1.find(str2))str_find()

请添加图片描述


http://www.mrgr.cn/news/5159.html

相关文章:

  • 商业软件许可证介绍|简单原理探究
  • 6.MySQL的增删改查
  • QT中使用QAxObject类读取xlsx文件内容并显示在ui界面
  • 【K8s】Java项目部署时为什么要用k8s?
  • 身份证OCR-身份证OCR识别-身份证OCR文字识别-身份证识别--身份证图像识别-身份证信息识别接口
  • python实现链表
  • 设计模式-责任链模式
  • Python类的介绍
  • 实现Linux的高可用负载均衡
  • 【云原生】企业级WEB应用服务器TOMCAT
  • 在VS Code中使用Snippet Craft扩展提高编码效率
  • 论文阅读:MonoScene: Monocular 3D Semantic Scene Completion
  • vue生命周期函数
  • 探索提示工程 Prompt Engineering的奥妙
  • git常用操作合集
  • SparkContext与SparkSession区别
  • Redhat8 搭建Zabbix6(二)优化
  • 移情别恋c++ ദ്ദി˶ー̀֊ー́ ) ——6.vector(模拟实现)
  • Spring Boot 中动态数据源配置与使用详解
  • 3-1 介绍及传感器(智能应用篇)