I'm trying to understand multiple function calls in python but kind of confused.
For example if there is two string variables called Work and Play and I wrote multiple function calls like:
Work.find(Play.strip().split()[0])
Does this mean like
or does it mean
Or does Python execute call() functions as they are written?
Thank for the help
strip() is called on Play, split() is called on that, and the first returned value from the split call is passed as an argument into the find() call on Work.
Think of the things in the parentheses as an expression that is passed into the call of find(). We could expand this code:
Work.find(Play.strip().split()[0])
To be:
strip_result = Play.strip()
split_result = strip_result.split()
argu = split_result[0]
Work.find(argu)
The first code bit is a lot more compact, but the second is more readable. You should check PEP 8 and your own preference to determine which to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With