Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Python bool() Function | Boolean Type
Python Data Types

book
Python bool() Function

In Python there is bool() function that converts variables of any type into a variable of boolean type (True or False). Let's look at an example for better understanding.

python
Input:
zero = 0
print(bool(zero))

Output:
False
python
Input:
one = 1
print(bool(one))

Output:
True
python
Input:
number = 10
print(bool(number))

Output:
True

Any digit other than zero is True.

python
Input:
x = None
print(bool(x))

Output:
False
Aufgabe

Swipe to start coding

You have three numbers of different numeric types, you have to return a boolean object from each of one.

Lösung

num_1 = 0
num_2 = 0j
num_3 = -376
num_4 = -89.4
num_5 = 32

print(bool(num_1))
print(bool(num_2))
print(bool(num_3))
print(bool(num_4))
print(bool(num_5))

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 2
num_1 = 0
num_2 = 0j
num_3 = -376
num_4 = -89.4
num_5 = 32

print(_ _ _(num_1))
print(_ _ _(num_2))
print(_ _ _(num_3))
print(_ _ _(num_4))
print(_ _ _(num_5))

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

We use cookies to make your experience better!
some-alt