Skip to content

Tag: string

Best practice when substring is missing from string

I’m extracting data from an API and one of the fields is a string from which i want to extract multiple substrings(7 ideally). To get those substring I’m using the index() method. There could be cases when one or more of these substrings(Reason ,Improvements_Done, Improvements_Planned etc) could be missing from the string. For example if “Improvements_Planned” is missing then i

Tuple comparison in function

I am wondering why my comparison returns False and not True although ‘a’ == ‘a’. Output: False Answer It’s because you are using *values rather than values in your function definition When you use the special syntax *args in a function, args will already come back as a tuple, where each arg is an element of the tuple. So for