#๐Ÿ”’ Baiscs

65 messages ยท Page 1 of 1 (latest)

tacit siren
#

Could someone explain how bool is related to numbers?

burnt nightBOT
#

@tacit siren

Python help channel opened

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.

rose oracle
#

!e py print(bool.mro())

burnt nightBOT
rose oracle
#

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.

tacit siren
#

I mean I did 6 + 5 the result is 2

#

I don't understand it

rose oracle
#

bool will return either True or False.

tacit siren
#

But it accepted the value

fallow prism
#

if >0 its true

rose oracle
#

If you give it a falsy object, bool will return False.

#

If you give it a truthy object, bool will return True.

fallow prism
rose oracle
#

In terms of numericals, 0 is falsy, nonzeroes are truthy.

#

Including negatives.

tacit siren
#

Bro I don't understand that I want to only know how 6+5 is 2

#

and 5 is bool

fallow prism
tacit siren
#

What 5 to bool becomes?

fallow prism
#

bools of any number except 0 return true

#

true

#

and true is interpreted as 1

rose oracle
#

!e py for v in (-2, -1, 0, 1, 2): print(v, bool(v))

tacit siren
#

;-;

burnt nightBOT
tacit siren
#

Yo wth

rose oracle
#

and True is 1 like.

tacit siren
#

How 4 is 1 then

rose oracle
#

4 is truthy.

#

It's nonzero.

#

Truthy objects given to bool make it return True.

#

True is 1 like.

fallow prism
#

good explanation

tacit siren
#

Wow thanks man

#

Is Python easy or hard?

rose oracle
#

Yes.

fallow prism
tacit siren
#

Who should I believe now?

fallow prism
#

prob the most beginner friendly language that isnt scripting

#

or web dev

tacit siren
#

So, Python is easy or hard?

rose oracle
#

!e py print(True + True + True)

burnt nightBOT
rose oracle
tacit siren
#

.-.

rose oracle
#

It's generally considered as easy.

tacit siren
#

Cool

fallow prism
#

!e
print(false + false + false)

burnt nightBOT
# fallow prism !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 "/home/main.py", line 1, in <module>
003 |     print(false + false + false)
004 |           ^^^^^
005 | NameError: name 'false' is not defined. Did you mean: 'False'?
rose oracle
#

But you will have difficulties along the way.

tacit siren
#

I know bool expressions

fallow prism
#

!e
print(False + False + False)

burnt nightBOT
tacit siren
#

I've learnt Java like OOP and basics

#

I am learning Python now

fallow prism
#

how did you learn java without learning booleans?

tacit siren
#

I learnt booleans but first time to see that you can convert booleans to int

fallow prism
#

also why were you turning numbers to bools anyways

tacit siren
#

;-;

tacit siren
burnt nightBOT
#
Python help channel closed for inactivity

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.