 # What are A and B in programming?

## Question

What are A and B in programming?

In the graphic shown here we can think of A and B as statements.

In programming, a statement can be thought of as something that has some result. Take, for example, what we’ve been writing so far: `10 < 1` results in `False`, or `(30 + 1) != 3` results in `True`.

So A and B are just statements like those, and they can be as complex as you want. Then we use `and`, `or`, and `not` as operators on these statements to make what we call expressions. An expression is just something that results in some value, `True` or `False` in this case.

If you want a challenge, take a look at the example below that’s a bit more than what we’ve done so far. If it doesn’t make sense, that’s totally fine! You will understand it in the exercises to come!

``````left_half  = (100 + 10) >= (20 - 5)  # True
right_half = (25 / 5) == 70  # False
bool_complex_false = left_half and right_half  # True AND False is False!
``````
9 Likes

A and B here are Statements . Its generally known as “PREPOSITION”.
A preposition is an atomic sentence which can result either true or false and nothing else .
eg. A= its Sunny outside.
B= My father is not at home .
you can see the answers to the statement A and B can either be true or false and nothing else . In computer language the value given to A and B are 0(false) and 1(true). By these values we can form premises.

3 Likes

Not to be overly semantic, this is a statement…

``````left_half  = (100 + 10) >= (20 - 5)
``````

and this is an expression

``````(100 + 10) >= (20 - 5)
``````

It is the expression that yields a value, not the statement, which only assigns the value to a variable.

``````result = A and B
``````

Above, `A` and `B` represent expressions (which can also be literals), with `and` being the logical AND operating on the two operands.

5 Likes

Thanks guy! It is very helpful to me.

So what you guys are saying is the A and B are statement in this situation but…

they can also be expressions too?

To clear the confusion, they and not statements, but expressions. The lesson text is incorrect.

A and B in logical expressions are called operands, but they too are expressions.

``````"A"
``````

is known as a string expression, which in logical terms is truthy since the string has a length greater than zero.

``````a + b
``````

is an expression, that represents a value. All expressions represent a value whether it is numeric, string, boolean, data structure or anonymous function (lambda). All expressions have a logical value, as well… truthy or falsy.

Consider,

``````>>> a, b = 6, 7
>>> a + b > b + a
False
>>> a * b > b * a
False
>>>
``````

The first line is a statement, the second and third are expressions.

As mentioned earlier, statements do not have a value. They are an instruction step. Notice how the last two lines echo a value, that is the evaluation of the expression.

The bottom line is that we can use all manner of expressions to construct a logical expression. It will all boil down to a single boolean value.

3 Likes

Thanks, this made it very clear.
In the first line of your answer, you meant they are not statements, instead of they and not statements, Right?

1 Like

Right. You read correctly. Lots of that typo disparity in dyslexia. The work never ends.

2 Likes