Размер шрифта
-
+

Python Handbook For Beginners - стр. 10


result = "apples" == "oranges"

print(result)


Run the above code in the console and see what it returns. Let's break it down.

I've created a variable named result in this code and assigned it a Boolean value from comparing the two strings "apples" and "oranges ".

Then I went down one line and printed the value of the "result" variable on the screen, passing the variable name in parentheses to the print function.

Does it make sense?) Now, alter the code by indicating that apples and oranges are not equal. What does the program return?

4 Comparing Variables

Not only can we compare numbers and strings, but the entire variables too! See how we can do it:


fruit = "Kiwi"

result = fruit == "Apple"

print(result)


Before you write the code into the console and hit enter, think of what output it will return? Let's break it down:

Страница 10
Продолжить чтение