Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Boolean Values | Loops
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python Ninja

bookBoolean Values

Swipe to show menu

Before going further, you will explore something new about Python.

Ninja's Surroundings

To help the Ninja navigate the map, you can look at the cells around it. The following methods let the Ninja check what is nearby:

  • object_up() checks the cell above the Ninja;
  • object_down() checks below;
  • object_left() checks to the left;
  • object_right() checks to the right.

Each method returns a string describing the object in that cell: "wall", "sushi", or "empty".

String Comparisons

In Python, you can compare strings using:

  • == checks if two strings are the same;
  • != checks if two strings are different.

The result of these comparisons is a boolean value.

Boolean Values

In Python, a boolean is a type of value that can be one of two things: True or False.

Since functions like object_up() return strings you can check what the Ninja sees and turn that information into something your code can use:

Is there sushi to the right? β†’ True or False:

ninja.object_right() == "sushi"

Is there a wall to the left? β†’ True or False:

ninja.object_left() == "wall"
question mark

What happens first on this line of code?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

SectionΒ 4. ChapterΒ 4
some-alt