1:输入一个字符串,求出这个字符串中空格的数量 “abc def gh"

这是Python题,大哥帮帮我

kong = 0

str = input("输入一串字符串: ")

for i in str:

    if i.isspace():

        kong += 1

print("空格: ", kong)

在Python中,isspace()是用于字符串处理的内置方法。如果字符串中的所有字符均为空格字符,则isspace()方法返回“True”,否则,返回“False”。

这个函数用于检查参数是否包含所有空格字符,例如:' ' - 空间、‘\ t’-水平标签、‘\ n’-换行符、‘\ v’-垂直标签、‘\ f’-提要、‘\ r’-回车

用法:

string.isspace()

参数:

isspace() does not take any parameters

返回:

1.True- If all characters in the string are whitespace characters.

温馨提示:答案为网友推荐,仅供参考
相似回答