-1

Hi I have a quick question regarding 'if not ..' in py.

This is a function that should take a list of strings and return a string.

I wondered what does the first line(if not strs) do? I guess it checks if the input list strs is empty or not? How does it work? Doesn't 'if not' check if it is opposite of expected value, like 'if not None'? Thank you!

def longestPrefix(strs):

        # Empty list
        if not strs: return ""
         ....
0

1 Answer 1

1

Empty strings are False in Boolean context, therefore if not False is True

Sign up to request clarification or add additional context in comments.

2 Comments

Ummmm, not [False] is False.
@StephenRauch sorry man i will edit that, i meant the brackets as place holders, like if not False is True , but i wanted to show that the False is the empty string

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.