99% Python developers will get confused!

preview_player
Показать описание
#shorts

python, C, C++, Java, JavaScript and Other Cheetsheets [++]:

►Learn in One Video[++]:

►Complete course [playlist]:

Follow Me On Social Media
Comment "#HarryBhai" if you read this 😉😉
Рекомендации по теме
Комментарии
Автор

a = (True, True, True)
a is a tuple with 3 true values
In python, whenever you write anything with commas, it converts it into a tuple
now, "a == True, True, True" is in of itself a tuple, with its 0th element being "a == True", and 1st and 2nd being "True" each.
that's why the 0th element evaluated to false (as a != True but it is equal to a tuple as mentioned above) and rest of the values remained the same.
Thats why we get (False, True, True) at the end.
Bonus: And if you run "a == (True, True, True)" with the brackets, it would just return True, which is expected in the first case.

krishgarg
Автор

it is like this
first statement : a = ( True, True, True )
Second Statement : ( a == True ), True, True

gamingvector
Автор

Eagerly waiting for your javascript course 🔥🔥

ansh_aditya
Автор

a = (True, True, True)
a is a tuple with 3 true values
In python, whenever you write anything with commas, it converts it into a tuple
now, "a == True, True, True" is in of itself a tuple, with its 0th element being "a == True", and 1st and 2nd being "True" each.
that's why the 0th element evaluated to false (as a != True but it is equal to a tuple as mentioned above) and rest of the values remained the same.
That's why we get (False, True, True) at the end.
Bonus: And if you run "a == (True, True, True)" with the brackets, it would just return True, which is expected in the first case.

nivealokhande
Автор

in the condition
a == True, True, True
It is comparing True as a boolean with tuple a, hence False. Other 2 Trues are booleans and different 2 different conditions.
The other 2 Trues are like saying
while True:
or if True:
That is, not checking for a particular condition. Just putting True.

So, it is not comparing a with True, True, True tuple.
We r in python repl. So if we type any value, whether boolean or tuple or list, it will be printed.
So a == True, True, True
Is a new tuple of values False, True, True. False is evaluated, other two put as it is.
To compare we need to write
a==(True, True, True)

thegreatprogrammer
Автор

Here goes like this
First statement : a = ( True, True, True )
Second Statement : ( a == True ), True, True

Comparing These Two results in the output given

karthikeyan
Автор

because it is checking a tuple with only a integer
like
a =(True, True, True)

but it is second statement
a==True, True, True
it is comparing a tuple only with first value
like ((True, True, True)==True) True True
so thats why it is showing result as (False, True, True)

devkaranjoshi
Автор

Operator precedence. You're actually checking equality between (True, True, True) and True in your second code snippet, and then building a tuple with that result as the first item.

Recall that in Python by specifying a comma-separated "list" of items without any brackets, it returns a tuple:

>>> a = True, True, True
>>> print(type(a))
<class 'tuple'>
>>> print(a)
(True, True, True)
Code snippet 2 is no exception here. You're attempting to build a tuple using the same syntax, it just so happens that the first element is (True, True, True) == True, the second element is True, and the third element is True.

So code snippet 2 is equivalent to:

(((True, True, True) == True), True, True)

And since (True, True, True) == True is False (you're comparing a tuple of three objects to a boolean here), the first element becomes False.

PrinceRapper
Автор

It is because a is tuple, and a==True condition gives False result and False, True, True returns, which is also a tuple.

jatingupta
Автор

In first statement we are giving value to variable :
a = true, true, true
and in second statement we are comparing variable : a == true, true, true

journeyofaa
Автор

First comma separated value is treated as first element of the tuple, so "a == True" and next two Trues are three elements of the tuple and a new tuple is being generated. And a == True should be evaluated as False so finally (False, True, True) was generated.

Harry Bhai 🤗

dipeshsamrawat
Автор

Bcoz
a==true, is condition which is false hence print false
Remains are simply printed as a tuples

SahilSharma-myyg
Автор

As in first statement

You are declaring variable a = True, True, True
Where as in second value you are comparing value by its variable datatype

kanishkkumar
Автор

may be this happened because in first code you wrote a=true which means the variable a have a string true but in second code you wrote a== true which means the value of a and true is same its not because a is not defined.

LiveRosemat
Автор

Comma separated values type karo to woh Tuple ban jata hai. Pehle (True, True, True) ek Tuple ban gaya aur variable a ko assign hua. Baad mein ek naya Tuple ban raha hai, jismein pehla value hai a==True ka evaluation. But a=(True, True, True). So a==True evaluates to False. This is added as the first value of the new Tuple being created. The remaining values come as they are given, i.e., if we type
a==True, 5, 4, True
then this will be printed:
(False, 5, 4, True)

but if we type
a=(True, True, True)
then it will print just:
True

VaibhavShete
Автор

Ek dam solid hero lag rahe ho Harry bhai lerning ke sath entertainment bhi ho raha hai 🤟

nilesh
Автор

You cannot compare with more than one values at a time and secondly it's a tuple so you have to give the index with it to compare with a particular value otherwise it will return false.

satyamkarn
Автор

1st case= true word store in a and print value of a and others true just print.
2nd case= now == sign use as a operator. Now that's why 1st is print is false and others normal print true

puspendumaji
Автор

1) >>> a = True, True, True -> tuple of "a" i.e. (True, True, True)
2) >>> a == True, True, True -> returns tuple ( False, True, True)

the first value is false (in 2nd) because we are comparing tuple of "a" i.e. (True, True, True) to a boolean True i.e. a == True

baxsm
Автор

Sencond statement: a==True, True, True
The first true is compared with a and the rest of the True are printed so it show False at first and the second and third True

Rahulraj-vukq