python基础练习题之字符串下标索引取值
摘要:"""找出单词 “world” 在 字符串"Hello, world" 中出现的位置,找不到返回-1从下标0开始索引 str.index()"""a = "Hello, world"print(a.index("w"))print(a.index("world"))print(a.index("e"
阅读全文
posted @
2022-02-23 22:06
peijiao
阅读(326)
推荐(0) 编辑
python基础练习题之拼接字符串列表
摘要:# 使用join"""有个字符串"abc"如何把字符串单个字符串联起来得到字符串 "a_b_c""""b = "abc"print("_".join(b))print(type(b))"""有个列表 ["hello", "world", "你好"]如何把列表里面的字符串联起来,得到字符串 "hell
阅读全文
posted @
2022-02-16 21:51
peijiao
阅读(440)
推荐(0) 编辑
python基础练习题之判断字符串回文
摘要:"""回文的定义: "回文"就是正读倒读都一样的。如奇数个: "98789" ,这个数字正读是"98789" 倒读也是"98789"。偶数个数字"3223"也是回文数。字母 "abcba" 也是回文。判断一个字符串是否是回文字符串,是打印True, 不是打印False"""# 是回文 判断为True
阅读全文
posted @
2022-02-14 15:02
peijiao
阅读(476)
推荐(0) 编辑
python基础练习题之字符串位置交换
摘要:'''已知 a的值为“hello”, b的值为“world”, 如何交换 a和 b 的值交换后 a的值为“world”, b的值为“hello”'''# 方法一# = 是赋值语句# 中间变量a = "hello"b = "world"zhi = aa = bb = zhiprint(a,b)# 方法
阅读全文
posted @
2022-02-13 10:35
peijiao
阅读(1146)
推荐(0) 编辑
python基础练习题之99乘法表
摘要:"""99乘法表"""# a = range(10) # 可迭代对象for i in range(1, 10): # print(i) # 行数 for j in range(1, i+1): # print("列数:", j) print("%s * %s = %-2s" % (j, i, j*i
阅读全文
posted @
2022-02-12 09:06
peijiao
阅读(103)
推荐(0) 编辑