码迷,mamicode.com
首页 > 其他好文 > 详细

字符串与字符 in --- not in

时间:2018-05-29 23:36:09      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:else   存在   字符   not   必须   name   style   print   span   

in与not in是判断一个东西是否存在另一个东西内:

in的用法:

name="忍者神龟"                                                                         "忍者神龟":为字符串

if "忍者" in name:                                                                           忍:为字符串里的字符

  print("是子字符串")                                                                "忍者":为子字符串       (子字符串里的字符必须是连着的)

else:                                                                                            "忍龟":则不是子字符串

  print("不是")

not in 的用法:

name="忍者神龟"

if "忍龟" not in name:

  print("不是子字符串")

else:

print("是子字符串")

 

字符串与字符 in --- not in

标签:else   存在   字符   not   必须   name   style   print   span   

原文地址:https://www.cnblogs.com/jiaqing767418611/p/9108522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!