Do You Actually Know Python?? #python #coding #programming

preview_player
Показать описание
This short video explains the exclusive or (xor) operator and how it may be confusing with the power operator.

Background Music:
Creative Commons Attribution 3.0 Unported License
Рекомендации по теме
Комментарии
Автор

This is why I code every day and still don't call myself a programmer.

QuestioningYourSanity
Автор

Hahaha
You can't fool me
^ is a bitwise XOR operator, not an exponent.

nbxl
Автор

I knew what it was, i just had no idea what it does

yesil_hiyar
Автор

“how well do you actually know python” sir, i use C++

stormswindy
Автор

Fun fact: the boolean equivalent of a bitwise XOR operator is the inequality operator != .
This can be used, for example, to check whether two numbers are both negative (same sign), both positive (same sign), or one is positive while the other is negative (different signs):

if (a < 0) != (b < 0):
# one is positive and one is negative (different signs)
else:
# both positive/both negative (same sign)

This is also how the bitwise operation works on individual bits, which can only be 1 (True) or 0 (False), so if they're the same, you get 0 (False) as the output, else you get 1 (True).

It follows that if ^ is for bitwise XOR, and != is the boolean equivalent, then == is the boolean opposite, which means ~(a ^ b) is the bitwise opposite (only selects the bits that are equivalent):

^



a&b - selects bits that are set in both a and b

~(a&b) - selects bits that are NOT set in a or NOT set in b or NOT set in both a and b

a|b - selects bits that are set in a or set in b or set in both a and b

~(a|b) - selects bits that are NOT set in both a and b

a^b - selects bits that are NOT equal in a and b, i.e. set in a or set in b, but NOT set in both a and b

~(a^b) - selects bits that are equal in a and b, i.e. NOT set in a and NOT set in b, or set in both a and b

The only potential problem with ~ is the fact that it will flip hidden leading 0s to leading 1s, which results in a negative value, so beware!

epsi
Автор

Started with C, so i know the Bitwise Operators, can't fool me 😎

floskater
Автор

How I managed to forget the bitwise XOR operand? I thought since this is a quiz question about Python, there must be something about "pythoning" features. It ends up about simple logic in any programming language

heroes-of-balkan
Автор

even though i know the answer to this my math brain always tells me that it is an exponent

juxyper
Автор

Dude that's crazy I have been studying python for a short while I plan on making it my career I actually did this one correctly

tatejackson
Автор

Im lucky I watched a video on that just last week 😎

ByteBeacon
Автор

Whoops. I knew it was a bitwise, but thought it was OR not XOR

ThethDoctor
Автор

I believe XOR is pronounced "ex or" as in 'exclusive or'.

adkharu
Автор

Damn most people are still misunderstanding ^ is exponential

NamNguyen-mzyh
Автор

People dont confuse ^ with ^ ^ . ^ is XOR and ^ ^ is power

Rahruma
Автор

Somehow even though I knew that the Python operator for raising a number by a power is double star (**). I didn't notice the mistake until it was shown.

pyp
Автор

XORing any value by itself is 0 btw so it’s not really “in our case” like he said it’s just always like that

bgxhylo
Автор

i didn't know about this and thought it will return an error

irpex
Автор

btw the square of (x-1) would be:
(x-1)**2

sensiblermensch
Автор

Hmmm. Seems I need to take out Python for dinner more often.

fruitfcker
Автор

I confused ^ with / and still got it right

theliteralcow