Booleans and null (Python)

Booleans and null

> Tutorial

You have seen that it is possible to manipulate numbers, but there are also special values: None and booleans.

None value

None is a value representing an empty, invalid or even an error value, but it is different from the number 0.

For example, me.weapon returns the weapon your leek is holding, or None if you don't have a weapon in your hands.

You may have noticed that me.setWeapon() costs 1 TP per turn. It is possible to limit its use to turn 1 with this condition:

We test a None value with is None (and is not None for the opposite).

Booleans: True and False

Booleans are two values: True and False. These are two values that can be used to represent something that can have two states like:

Examples of properties and methods that return a boolean:

Example: we check if we can use our weapon on the enemy:

❓ Quiz

What can None be used for?

Representing a lack of information/value Represent the number 0 Represent an error Representing a poor quality program

What are booleans for?

Represent a value with two possible states Represent a very high value

Full AI