isalpha python function won't consider spaces

前端 未结 1 974
挽巷
挽巷 2020-12-19 03:24

So the code below takes an input and makes sure the input consists of letters and not numbers. How would i make it also print orginal if the input contains a space



        
相关标签:
1条回答
  • 2020-12-19 03:41

    It looks like that's just how string works.

    Two options:

    if all(x.isalpha() or x.isspace() for x in original):
    

    (modified on inspectorG4dget's recommendation below)

    or

    original.replace(' ','').isalpha()
    

    should work.

    0 讨论(0)
提交回复
热议问题