How to remove "" from starting of a string if provided by the user

Serhiy Storchaka storchaka at gmail.com
Thu Aug 13 02:28:04 EDT 2020


12.08.20 18:53, MRAB пише:
> I would suggest:
> 
>>>> while s[ : 1] in {'"', "'"} and s[ : 1] == s[-1 : ]:
> ...     s = s[1 : -1]

And the condition can be written as

    s[ : 1] == s[-1 : ] in {'"', "'"}

or more efficiently as

    s and s[0] == s[-1] in '\'"'



More information about the Python-list mailing list