![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
python学习
Miss. Zing
在人生的更高处相见
展开
-
python去除字符串空格
#方法一:str1 = " ac v b "res = str1.split() #以空格为分隔符 返回一个列表对象print(res) #['ac', 'v', 'b']s = "".join(res)print(s)#方法一:wordlist = ["it ajsn","k js db ","as kd k"," jsd"]for list1 in wordlist: word = list1.replace(" ","") print(word ,en.原创 2021-05-04 09:00:44 · 225 阅读 · 0 评论 -
python统计一个字符串中出现的字符及其个数
#列表str1 = input("请您输入字符串:")list1 = list(str1)#列表的去重s = set(list1)for i in s: #只会遍历列表中的元素一次 print(f"{i}字符出现了{list1.count(i)}次")#字典str1 = input("请您输入字符串:")s = {}for i in str1: if i in s: s[i] += 1 else: s[i] = 1# prin.原创 2021-05-03 20:49:52 · 2872 阅读 · 0 评论