#๐ Baiscs
65 messages ยท Page 1 of 1 (latest)
@tacit siren
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!e py print(bool.mro())
:white_check_mark: Your 3.13 eval job has completed with return code 0.
[<class 'bool'>, <class 'int'>, <class 'object'>]
This shows that bool inherits from int, which in turn inherits from object.
True is 1 like. False is 0 like.
Similar data to ints, but with a type of bool.
So, in answer to your question, inheritance.
bool will return either True or False.
But it accepted the value
if >0 its true
If you give it a falsy object, bool will return False.
If you give it a truthy object, bool will return True.
and true = 1
you turn them into bools
What 5 to bool becomes?
!e py for v in (-2, -1, 0, 1, 2): print(v, bool(v))
;-;
:white_check_mark: Your 3.13 eval job has completed with return code 0.
001 | -2 True
002 | -1 True
003 | 0 False
004 | 1 True
005 | 2 True
Yo wth
and True is 1 like.
How 4 is 1 then
4 is truthy.
It's nonzero.
Truthy objects given to bool make it return True.
True is 1 like.
good explanation
Yes.
syntax looks easy
Who should I believe now?
So, Python is easy or hard?
!e py print(True + True + True)
:white_check_mark: Your 3.13 eval job has completed with return code 0.
3
It is both.
.-.
It's generally considered as easy.
Cool
!e
print(false + false + false)
:x: Your 3.13 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File [35m"/home/main.py"[0m, line [35m1[0m, in [35m<module>[0m
003 | print([1;31mfalse[0m + false + false)
004 | [1;31m^^^^^[0m
005 | [1;35mNameError[0m: [35mname 'false' is not defined. Did you mean: 'False'?[0m
But you will have difficulties along the way.
I know bool expressions
!e
print(False + False + False)
:white_check_mark: Your 3.13 eval job has completed with return code 0.
0
how did you learn java without learning booleans?
I learnt booleans but first time to see that you can convert booleans to int
also why were you turning numbers to bools anyways
;-;
Idk just tried it xd
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.