Building Complex Expressions
00:00 It’s all very well to read and to listen and absorb all this information about Boolean comparators, logical operators, operator precedence, but until you actually get your hands dirty and see it in action, it’s never really going to sink in. So in this lesson, you’re just going to look at a couple more examples of some more complex expressions.
And that’s just not to give the game away. We want to try and work out what this is without actually executing it first. So how would you go about understanding a complex expression like this? Well, let’s break it up into little pieces. You know that operations in brackets (
()) evaluate first.
So what does
1 != 1 evaluate to?
1 != 1 gives
1 is equal to
1. So now you can rewrite the expression as
True and not
False. So what’s next—
not is next. What does
not False evaluate to?
How do you break it up? Well, you start off with the things in brackets. Look at the first one.
"a" != "a". It gives you
False because the string
"a" is equal to the string
"a". So now you can rewrite the whole expression as
or not (2 >= 3).
So what’s next? It’s the other expression in brackets:
2 >= 3. So does that expression evaluate to
2 greater than or equal to
3? No, that’s wrong.
2 is not greater than or equal to
3. It’s less than
3, so that will give you a
03:57 You just went through a couple of examples showing you how to figure out step by step how a complex expression evaluates. You’ve taken your knowledge of operator precedence and applied it to these expressions to see which ones go first and how it reduces into its final value.
04:16 To really internalize all of this, the best thing is to practice. Come up with your own complex expressions, use variables to store the values of expressions, assign the results of expressions to variables, mix and match.
Become a Member to join the conversation.