Using len for text but discarding spaces in the count

后端 未结 7 1334
天命终不由人
天命终不由人 2020-12-10 20:44

So, I am trying to create a program which counts the number of characters in a string which the user inputs, but I want to discard any spaces that the user enters.



        
7条回答
  •  星月不相逢
    2020-12-10 21:06

    To count the number of characters excluding spaces, you can simply do:

    >>> full_name = "John DOE"
    >>> len(full_name) - full_name.count(' ')
    7
    

提交回复
热议问题