Logical Types
Let's now turn our attention to logical data types.
For instance, if you evaluate 2 > 1
, it will return TRUE
because 2
is indeed greater than 1
. This principle will be highly relevant in later chapters.
Numbers and strings (text) can also be converted to logical types. Any number except 0
will be converted to TRUE
(0
converts to FALSE
), and the strings 'F'
, 'false'
, 'False'
, and 'FALSE'
will convert to the logical FALSE
. The same principle applies for logical TRUE
.
When converting logical values to numbers, FALSE
becomes 0
, and TRUE
becomes 1
.
Swipe to start coding
- Assign the result of the expression
19*54 > 76*13
to the variablelogic
. - Show the value of the
logic
variable. - Show the data type of the
logic
variable. - Convert the
logic
variable to an integer and show the result.
Avoid using the print()
function.
Løsning
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 3.85Awesome!
Completion rate improved to 3.85
Logical Types
Let's now turn our attention to logical data types.
For instance, if you evaluate 2 > 1
, it will return TRUE
because 2
is indeed greater than 1
. This principle will be highly relevant in later chapters.
Numbers and strings (text) can also be converted to logical types. Any number except 0
will be converted to TRUE
(0
converts to FALSE
), and the strings 'F'
, 'false'
, 'False'
, and 'FALSE'
will convert to the logical FALSE
. The same principle applies for logical TRUE
.
When converting logical values to numbers, FALSE
becomes 0
, and TRUE
becomes 1
.
Swipe to start coding
- Assign the result of the expression
19*54 > 76*13
to the variablelogic
. - Show the value of the
logic
variable. - Show the data type of the
logic
variable. - Convert the
logic
variable to an integer and show the result.
Avoid using the print()
function.
Løsning
Tak for dine kommentarer!
single
Awesome!
Completion rate improved to 3.85
Logical Types
Stryg for at vise menuen
Let's now turn our attention to logical data types.
For instance, if you evaluate 2 > 1
, it will return TRUE
because 2
is indeed greater than 1
. This principle will be highly relevant in later chapters.
Numbers and strings (text) can also be converted to logical types. Any number except 0
will be converted to TRUE
(0
converts to FALSE
), and the strings 'F'
, 'false'
, 'False'
, and 'FALSE'
will convert to the logical FALSE
. The same principle applies for logical TRUE
.
When converting logical values to numbers, FALSE
becomes 0
, and TRUE
becomes 1
.
Swipe to start coding
- Assign the result of the expression
19*54 > 76*13
to the variablelogic
. - Show the value of the
logic
variable. - Show the data type of the
logic
variable. - Convert the
logic
variable to an integer and show the result.
Avoid using the print()
function.
Løsning
Tak for dine kommentarer!