vl = "我是中国人" #判断中国是否在vl代指的字符串序列中 vl = "中国" in value 实列: dd = input("请输入内容:") if "上门" in dd: print("包含敏感字符") 实例2: while True: dd = input("请输入内容") if "上门" in dd: print("包含敏感字符") else: print(dd) break
v = "oldboy" v1 = v[0] # 0 1 2 3 ... 从前向后 v2 = v[-1] # -1 -2 -3 ...从后向前
v = "oldboy" # v1 = v[2:4] # 2 =< 索引位置 <3 # v2 = v[3:6] # v2 = v[3:-1] # v2 = v[3:] # v2 = v[:-1] # print(v2) # 示例: 取最后两个字符 # data = input('请输入:') # 方式一 # v = data[-2:] # print(v) # 方式二 # total_len = len(data) # v = data[total_len-2:total_len] # print(v)