Nowadays, Python 3 is becoming more and more popular than Python 2, but there are still a lot of codes of Python 2 remained. Although we can use them on Python 2 or use pyenv to manage the versions of Python, but I still want to modify these codes to…
一.in的使用 in 操作符用于判断关键字是否存在于变量中 a = '男孩wusir' print('男孩' in a) 执行输出: True in是整体匹配,不会拆分匹配. a = '男孩wusir' print('男孩sir' in a) 执行输出:False 比如评论的敏感词汇,会用到in 和not in comment = input('请输入你的评论:') if '苍井空' in comment: print('您输入的有敏感词汇,请重新输入') 执行输出 请输入你的评论:苍井空 您输…
一.in的使用 说明:in有相当多的用处,比如判断,循环for 等. 实例一:in 操作符用于判断关键字是否存在于变量中 s = '男人john' print('男孩' in s) print('男孩john' in s) print('男人jo' in s) print('wusir' not in s) 执行后输出结果为: 注意:in是整体匹配,不会拆分匹配. 示例: a = '男孩John' print('男孩sir' in a) 执行输出:False 实例二:in 做关键字匹配 com…
一.in的使用 in 操作符用于判断关键字是否存在于变量中 a = '男孩wusir' print('男孩' in a) 执行输出: True in是整体匹配,不会拆分匹配. a = '男孩wusir' print('男孩sir' in a) 执行输出:False 比如评论的敏感词汇,会用到in 和not in comment = input('请输入你的评论:') if '苍井空' in comment: print('您输入的有敏感词汇,请重新输入') 执行输出 请输入你的评论:苍井空 您输…
一.in的使用 in 操作符用于判断关键字是否存在于变量中 ? 1 2 a = '男孩wusir' print('男孩' in a) 执行输出: True in是整体匹配,不会拆分匹配. ? 1 2 a = '男孩wusir' print('男孩sir' in a) 执行输出:False 比如评论的敏感词汇,会用到in 和not in ? 1 2 3 comment = input('请输入你的评论:') if '苍井空' in comment: print('您输…