小编Ste*_*son的帖子

使用Python计算字符串中的大写字母

我试图找出如何计算字符串中的大写字母.

我只能计算小写字母:

def n_lower_chars(string):
    return sum(map(str.islower, string))
Run Code Online (Sandbox Code Playgroud)

我想要完成的例子:

Type word: HeLLo                                        
Capital Letters: 3
Run Code Online (Sandbox Code Playgroud)

当我尝试翻转上面的函数时,它会产生错误:

def n_upper_chars(string):
    return sum(map(str.isupper, string))
Run Code Online (Sandbox Code Playgroud)

python string count python-3.x uppercase

22
推荐指数
4
解决办法
6万
查看次数

我如何排序,摆脱数字和组织?

如果我要求某人输入价值:

value = input("List numbers: ")
Run Code Online (Sandbox Code Playgroud)

我想组织它:

用户输入= 1,2,3,2

并得到一个1,2,3的print()作为结果 - 摆脱额外的数字
我将如何去做?
以及我如何组织它们?例如2 1 4 3 5并获得1 2 3 4 5的print()

python python-3.x

-1
推荐指数
1
解决办法
172
查看次数

标签 统计

python ×2

python-3.x ×2

count ×1

string ×1

uppercase ×1