Using len for text but discarding spaces in the count

后端 未结 7 1305
天命终不由人
天命终不由人 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:11

    Count the length and subtract the number of spaces:

    >>> full_name = input("Please enter in a full name: ")
    Please enter in a full name: john smith
    >>> len(full_name) - full_name.count(' ')
    9
    >>> len(full_name)
    

提交回复
热议问题