Why Is Python Not Pythoning??

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ • 924

  • @mathgeniuszach
    @mathgeniuszach 2 роки тому +4573

    Basic thing to remember: even though sometimes you can read Python like English, Python is not English.

    • @mage1over137
      @mage1over137 2 роки тому +111

      Yeah I actually thought this was a weird thing to cover. Of course you can't use "or" statements like that.

    • @happyhacker4737
      @happyhacker4737 2 роки тому +6

      Well said, man!

    • @DeepfriedBeans4492
      @DeepfriedBeans4492 2 роки тому +27

      @@mage1over137 I don’t think it’s that unreasonable for “or” to function like that in a programming language, obviously that’s not how it works here but it absolutely could function like that in some language

    • @jonathanalexander9881
      @jonathanalexander9881 2 роки тому +4

      This needs to be written in all caps on every billboard...

    • @happyhacker4737
      @happyhacker4737 2 роки тому

      @@jonathanalexander9881:)

  • @arturorg0
    @arturorg0 2 роки тому +2262

    I had to discover that by myself, I wish I knew that before 🤧

    • @view2me
      @view2me 2 роки тому +20

      Yeah, i needed to discover it the hard way 😔

    • @eagold
      @eagold 2 роки тому +4

      same was to me about a year ago

    • @gaminf6713
      @gaminf6713 2 роки тому +7

      Same here it took 3 days to discover in my code😭😭

    • @ko-Daegu
      @ko-Daegu 2 роки тому +4

      No u don’t
      This is the right way to learn

    • @hamynguyen3433
      @hamynguyen3433 2 роки тому +1

      Yah same, so painful :(((

  • @user-kj5cb1hh1d
    @user-kj5cb1hh1d 2 роки тому +871

    i managed to figure this out. not because im smart but because ive been dumb, many, many times

    • @Zatando1
      @Zatando1 2 роки тому

      Put that shit on a shirt

    • @Ryan-li1ro
      @Ryan-li1ro 2 роки тому +86

      that's the definition of a smart person, someone who has been dumb. don't beat yourself down!

    • @Heirloop
      @Heirloop 2 роки тому +13

      As long as you keep trying, then you’re doing good

    • @jbezuidenhout46
      @jbezuidenhout46 2 роки тому +4

      You have been quoted

    • @ST3W1010
      @ST3W1010 2 роки тому

      Nah your smart. You know you’ve been dumb many times. But you recognize and know that.

  • @cbworm
    @cbworm 2 роки тому +936

    Theres tricky things like this in almost every language! This was great to learn!

    • @blablabla7796
      @blablabla7796 2 роки тому +90

      I’m not sure if this is “tricky”. I come from a mostly C based programming languages and I’ve never seen a PL do x == 1 || 2 || 3 before. If anything, the ability to do that makes it tricky.

    • @rorymax
      @rorymax 2 роки тому +5

      @@blablabla7796 yeah but in python you can do things like 1

    • @pacifist1354
      @pacifist1354 2 роки тому +1

      @@rorymax Yeah and if I remember Python correctly (I’m a low level dev lol)
      if [‘Bob’, ‘Nancy’, ‘Tom’].contains(name):
      You could do something like that

    • @ДмитроМінтенко-м7и
      @ДмитроМінтенко-м7и 2 роки тому +7

      @@pacifist1354 you can use a tuple instead of a list to take up less memory and be faster for basically no cost and use the "in" thingy
      so it's better to do
      if name in ('Bob', 'Nancy', 'Tom')

    • @tbuk8350
      @tbuk8350 2 роки тому +5

      @@blablabla7796 Yeah, I was gonna say the same thing. The 'or' statement in Python is a direct replacement for '||'. It does the exact same thing. It would be tricky if it behaved differently for some reason (and that would make it harder to use).
      If you wanted to make an if statement check if someone's name is equal to a string, or their id is equal to an int, an "or" statement behaving like any other "or" statement makes that easy, but if it behaved the other way, you would not be able to compare two different variables with two different types without nesting if statement.

  • @joakimkaseva
    @joakimkaseva 2 роки тому +91

    These statements are almost always in other languages as if(name == "name1" or name == "name2") so seeing this statement immediately raises red flags

    • @YoshiAsk
      @YoshiAsk 2 роки тому +4

      It's also weird that Python lets you evaluate a string as a boolean

    • @gigachad8810
      @gigachad8810 2 роки тому +7

      @@YoshiAsk its called truthyness, its actually very useful. just makes code more concise

    • @ImmortalSpelldagger
      @ImmortalSpelldagger 2 роки тому

      ​@@gigachad8810 yea... Idk what u talking about but why its so confusing Like u cloud just put the strings into brackets with or

    • @SumSpr33
      @SumSpr33 2 роки тому

      thats what im saying bro why make it difficult

    • @antt2228
      @antt2228 Рік тому

      ​@@ImmortalSpelldaggerC/C++ does this type of stuff too

  • @zgliu8018
    @zgliu8018 2 роки тому +887

    Python: does something slightly not pseudo code
    People: why is Python not Pythoning????

    • @DarkNexarius
      @DarkNexarius 2 роки тому +44

      We really need the "anything pseudo code" to machine code programming language.

    • @rose-bz4nq
      @rose-bz4nq 2 роки тому +4

      what color is your buggati

    • @MrPuzzleCodes
      @MrPuzzleCodes 2 роки тому +21

      Its not even pseudo code lol you would still have to say:
      name is name1 or name is name2 or name is name3

    • @samueljehanno
      @samueljehanno 2 роки тому +2

      ​@@MrPuzzleCodeswat

    • @w花b
      @w花b 2 роки тому +5

      ​@@DarkNexarius powered by an AI interpreter

  • @caspermoon6052
    @caspermoon6052 Рік тому +6

    I actually ran into this issue and it stumped me for a week.
    Eventually someone told me that the other options arent being checked against the "name" variable.
    Thank you again for yet another great tutorial!

  • @sudo597
    @sudo597 2 роки тому +97

    can you do more of this simple tips in syntaxes please

  • @gustavomendez2891
    @gustavomendez2891 2 роки тому +118

    better to use a tuple over a list, since inmutables have better read, and creation speeds

    • @ryu_ge
      @ryu_ge 2 роки тому +8

      For performance-wise, I agree. But in data analysis, as long as the results are to be expected, it doesn't matter

    • @pleli
      @pleli 2 роки тому +20

      Not just performance. To the reader tuple means this is a closed list and should not be changed (the immutablilty is for the coder, not the machine)

    • @schlopping
      @schlopping 2 роки тому +34

      When checking for 3 values in python, your first thought definitely shouldn't be how to shave off a picosecond lol

    • @sagetarus1
      @sagetarus1 2 роки тому +1

      Why would it be better to create a tuple? This is a lost of users that have access to something. That list most definitely will change. It may be faster to create a tuple, but how many times are you going to have to create it, convert it, append, and make it a tuple once again?

    • @sangchoo1201
      @sangchoo1201 2 роки тому +5

      if it is literal (it is already known compile time), then use tuple.

  • @Rudxain
    @Rudxain 2 роки тому +13

    If the `list` only has 4 values, it's ok to use `in`, but if it gets bigger you should always use a `set` (replace `[]` by `{}`) because it's more efficient when using `in`

    • @maanavsingh1914
      @maanavsingh1914 2 роки тому +1

      Except that it’s O(n) to build the set anyways and it’s several times slower to build a set than linear scan a list…

    • @Rudxain
      @Rudxain 2 роки тому

      @@maanavsingh1914 That's why we should store the set in a variable, to ensure that any Python interpreter doesn't build the set every-time we access it. But, IIRC, CPython already recognizes constant sets, and uses memoization to avoid further re-computations

    • @maanavsingh1914
      @maanavsingh1914 2 роки тому

      @@Rudxain memorization refers to caching the results of a function. Doesnt haven’t much to do with this example. Sure if we had multiple invocations of this conditional check and there were a lot of names performance would improve but looking at this specific code that doesn’t apply. No static analysis by the interpreter can magically skip the instantiation cost of a set. You have to pay the cost at some point and it’s not worth it for this example.

    • @Rudxain
      @Rudxain 2 роки тому

      @@maanavsingh1914 I realized I used the wrong term: it's not memoization, it's lazy-evaluation with sharing.
      About the performance part, that's what I said! (Sort of) linear searches are faster than hash functions and logarithmic searches for small sequences of values

  • @Polarzz
    @Polarzz 2 роки тому +66

    that keyboard is so satisfying 😊

    • @jongeduard
      @jongeduard 11 місяців тому

      There actually exists a think like ASMR programming on YT.
      Although most of these codes will probably show you satisfying results instead. :P

  • @Febreeze419
    @Febreeze419 2 роки тому +33

    Reminds me of an error I had in java where the == operator didn't only check if the string was the same but if they had the same origin. So when I imported a name from another class it would always return false. Found out that you can just use object1.equals(object2).

    • @bhw_msq
      @bhw_msq 2 роки тому +10

      That is the actual way how you compare two strings in java

    • @Febreeze419
      @Febreeze419 2 роки тому +4

      @@bhw_msq Learnt it the hard way :(

    • @chase-2-2
      @chase-2-2 2 роки тому +1

      Yeah that's one of the really weird things about java and something that's luckily fixed in kotlin

    • @jongeduard
      @jongeduard 11 місяців тому +1

      Oh crap. That's true indeed. In C# you do not have that problem.
      And in Rust you have even less problems.

    • @robstamm60
      @robstamm60 11 місяців тому +1

      Haha yep that's the reason I consult the documentation every time I am doing a comparison in a language I don't use that often

  • @avgvstvs96
    @avgvstvs96 Рік тому +1

    Hey bool these videos are game changing, u got something really special here I hope you know that

  • @stonkodactyl9210
    @stonkodactyl9210 Рік тому +3

    The output will be “next time bring Bob, Tom, or Mike with you”

  • @TrendyBanana
    @TrendyBanana 2 роки тому

    This solved an issue I had for so long with making a password and username login, thank you so much!

  • @broxxad
    @broxxad Рік тому

    great stuff man, simple details like this make big impacts.

  • @beepbeepgamer1305
    @beepbeepgamer1305 Рік тому +3

    yeah, this used to be one of the problems I used to face but then I figured it out myself to use the in operator, you could use tuple or dictionary also but if it's a dictionary, it's only gonna check the key but not the value.

  • @ThePhantomCoder
    @ThePhantomCoder 2 роки тому

    Paused the video before the result, realized after a few seconds and felt so proud

  • @TheRapidDev
    @TheRapidDev 2 роки тому +14

    only real OG's knew the error before he told you

    • @Preetzole
      @Preetzole 2 роки тому +1

      Keep holding onto that dumb superiority complex. See if it does anything for you in life.

    • @incremental_failure
      @incremental_failure 2 роки тому +1

      This is basic stuff. The even better way is to use a tuple instead of list.

    • @twentyThirdofJuly
      @twentyThirdofJuly 2 роки тому

      wooow og

    • @TheRapidDev
      @TheRapidDev 2 роки тому

      @@incremental_failure I agree, for both things you said.

    • @TheRapidDev
      @TheRapidDev 2 роки тому

      @@ba7260 Yes, but the syntax is different with languages

  • @Shinigamischannel
    @Shinigamischannel Рік тому

    Thank you so mych for explaning this. Saved me so much trouble!

  • @ocsilentwolf7805
    @ocsilentwolf7805 Рік тому +7

    As a JavaScript developer Python looks easier to use.

    • @ButtFingerer3000
      @ButtFingerer3000 10 місяців тому

      While that is true javascript is way more powerful, efficient and fast than python.

  • @jongeduard
    @jongeduard 11 місяців тому +1

    When I see things like this I think 3 things...
    1. ALWAYS test your code, never asume.
    2. Python is still not as terrible with this kind of things as JavaScript with all it's weird type coercions. Here everything is translated into a boolean expression but in JS you can even confuse all kinds of numbers, strings and objects in weird ways.
    3. This is why programming languages with an actually strong and strict type system are best. You cannot make this type mistake in those languages, because it will not compile but fail immediately.

  • @orcishh
    @orcishh 2 роки тому +1

    Nice to know! I'm just starting to really learn coding and these shorts help a ton :)

  • @bartekgolczyk9203
    @bartekgolczyk9203 2 роки тому +16

    That’s why I like explicit typing and type safty so much

    • @the_agent_z
      @the_agent_z 2 роки тому +1

      rust user?

    • @ihaveakirbyobessesion2617
      @ihaveakirbyobessesion2617 2 роки тому +1

      Spill!

    • @jongeduard
      @jongeduard 11 місяців тому

      @@the_agent_z Rust is amazing, but you do not even need Rust to avoid this specific quite basic language design error.
      Even in C#, Java or Go your program is not going to compile.

  • @tamamlanmamis
    @tamamlanmamis Рік тому +1

    I did that when i first started programming but now I don't find myself making that mistake as often

  • @SH0QR
    @SH0QR 2 роки тому +3

    I already figured out by myself the name == "name", but I didn't know about the name in ["name"] is very helpful thankyou

  • @PanDiaxik
    @PanDiaxik 2 роки тому +2

    If it was any other language I would say it would print 'Access granted', but knowing that stuff like 2 < x < 6 works as expected in python I wans't sure here.

  • @emmettdja
    @emmettdja 2 роки тому +3

    Used to do this when I was first learning Javascript

  • @PixelDave0
    @PixelDave0 Рік тому

    U are really helping in my journey of learning python

  • @asdfghyter
    @asdfghyter 2 роки тому +3

    truthyness is always a footgun. I prefer when you need to explicitly coerce values

  • @faultline3936
    @faultline3936 Рік тому

    Currently learning Python and I came across this problem. Took me a good amount of time to figure out

  • @cringe1462
    @cringe1462 2 роки тому +5

    I really needed that information like 48 hours ago before I made ~30 elif's

    • @silitome3086
      @silitome3086 2 роки тому +1

      You should use switch statements

  • @BreadLoeuf
    @BreadLoeuf Рік тому

    Even as someone who knew this already, this question still threw me for a loop

  • @whamer100
    @whamer100 2 роки тому +3

    havent pressed play yet, its going to print access granted because non-empty strings are truthy

    • @whamer100
      @whamer100 2 роки тому

      yep was exactly right. good syntax video!

  • @YugoslaviaZambia
    @YugoslaviaZambia 2 роки тому +120

    I loved the part when Python said "It's python'ing time" and python'ed all over the place

  • @friedrichvillegasmurillo9775
    @friedrichvillegasmurillo9775 2 роки тому

    The fact that i already knew how to use the collection in the if statement amazes me a lot how easy is to use it.

  • @AquaQuokka
    @AquaQuokka Рік тому +3

    Reasoning behind this:
    Strings are always True, which means you are comparing True to True, which amazingly is True.
    Edit: In the context of this snippet, this is not correct. It is because 'Tom' and 'Mike' are strings, which evaluate to True, so it is actually checking for "if False or True", which means regardless it will return True.

    • @keith6293
      @keith6293 Рік тому

      Thanks! Was looking for this. ^^

  • @WWASHD
    @WWASHD 10 місяців тому

    I needed this for my calculator, tyvm!

  • @WolfireGaming
    @WolfireGaming Рік тому +6

    Back when I started learning programming, I ran into this exact issue. Now I work as a full stack engineer at one of the largest companies in the world. I don't say that to flex, but to say, you're going to make silly errors or not quite get something the first time. Programming is an activity you can (and probably will) fail at over and over, and as long as you hold onto that hunger to learn and don't let yourself get too discouraged, you'll be fine.
    I will flex about the fact that I asked about this error on stack overflow and made it out with all of my body parts still attached though.

    • @jongeduard
      @jongeduard 11 місяців тому

      Every programmer writing in some language with a loosely, dynamically or otherwise lacking type system is going to run in this type of problem.
      Definitely great for learning experience.
      But for me also a reason why I love languages with properly designed type systems so much.
      Safety over easiness.
      Finding your bugs early will be easier in the end.

  • @thehansboi
    @thehansboi Рік тому

    It's like google knew what problem i had in python

  • @urassari
    @urassari 2 роки тому +43

    i am literallly learning python from yt shorts

  • @kenridlycan6790
    @kenridlycan6790 Рік тому

    That's a really useful tip, thank you

  • @romantarnai4702
    @romantarnai4702 2 роки тому +3

    Isn't that a normal behaviour of chaining conditions ?

    • @corlaez
      @corlaez 2 роки тому

      It is and many languages will behave like that. Some with better type guarantees won't let that compile.
      It is still a good tip for the very beginning because that syntax reflects how we talk and in python it runs so it can cause bugs

    • @schlopping
      @schlopping 2 роки тому

      mhm, this video is just for ppl who aren't familiar with them. it's equivalent to kids first learning about why 2 + 2 * 2 isnt 8

    • @schlopping
      @schlopping 2 роки тому

      @@corlaez The "broken" code is still valid code though, and had 0 bugs. This isn't a good argument for static type checking. If it were to give a runtime error, I'd give you credit, but the code was completely valid

  • @zenyx11
    @zenyx11 Рік тому

    thank you, this really.helped me I was wondering why my if statement was returning true even if the input is false. this is very helpful specially for a begginer like me

  • @Joooooooooooosh
    @Joooooooooooosh 2 роки тому +129

    Ahh I too remember day 2 of being a programmer.

    • @marijn17s
      @marijn17s 2 роки тому +30

      toxic

    • @sunpoke5317
      @sunpoke5317 2 роки тому +22

      @@marijn17s why is that toxic, it's just a normal comment.

    • @creed404
      @creed404 2 роки тому +17

      @@sunpoke5317 you have to understand the deep meaning behind that comment

    • @sunpoke5317
      @sunpoke5317 2 роки тому +7

      @@creed404 none?

    • @klittlet
      @klittlet 2 роки тому +20

      @@creed404 it ain't that deep bro

  • @zikos3743
    @zikos3743 9 місяців тому

    This is actually how a teacher first told me about boolean values.
    I was trying to test if a character was 'a' or 'A' and ended up having an always true condition

  • @apurvaisnotcool
    @apurvaisnotcool 2 роки тому +14

    That's why I'm a fan of languages that don't force indentation.( C, C++ etc) because confusion like these are quite rare while coding in C++ even javascript.

    • @voodoo1094
      @voodoo1094 2 роки тому +3

      Fun fact (although the logical flaw in the reasoning here should be pretty obvious): If you add parens around the if (and add the type decl.) the code will compile in c++ and produce the wrong result as well (yep or has been a keyword for decades at this point).

    • @MrTrollo2
      @MrTrollo2 2 роки тому +3

      can you elaborate? This is the exact kind of error you'd get in almost any language - this might be stopped by more srict typing, but surely not by indentation, indents have nothing to do with lesser readability (how would forcing readability through indention be a disadvantage anyways?) nore semantics here.

    • @MrTrollo2
      @MrTrollo2 2 роки тому +4

      @@Rubyd777 i don't get it. This error has nothing to do with indention and would occur in the same way in C

    • @Rubyd777
      @Rubyd777 2 роки тому

      @John der Don oops sorry i mistakenly mentioned you

    • @jongeduard
      @jongeduard 11 місяців тому

      I would not try defend JS with anything like this. JS is fun, but it's absolute garbage language design with all it's type coercions. In Python you can still make boolean logic with everything apparently, but not twist everything like you can in JS.
      I prefer languages with actual proper type systems though.

  • @howsitben
    @howsitben 2 роки тому

    Thank you for this, was lost on this concept today

  • @abhinavreddyboddu6351
    @abhinavreddyboddu6351 2 роки тому +44

    And that's how any normal programming language works

    • @ImmortalSpelldagger
      @ImmortalSpelldagger 2 роки тому

      Lua is easier

    • @thomasn5726
      @thomasn5726 2 роки тому +4

      Exactly. The video showing why “Python is not programming” and showing something that doesn’t work in C++, C#, Java, JS, TS as well is just hilariously dumb

    • @chase-2-2
      @chase-2-2 2 роки тому +3

      Dynamically typed languages, yes. But statically typed languages (which are the majority) will throw a compiler error here

    • @AWriterWandering
      @AWriterWandering 2 роки тому +1

      @@thomasn5726 the video is why “Python is not Pythoning”. Yes, this is a common error in programming languages, but it’s a particular rough spot in a language that is generally touted for its readability.

    • @AWriterWandering
      @AWriterWandering 2 роки тому

      @@chase-2-2 well, it depends moreso on whether or not the language requires explicit conditionals. ‘name == “Bob” || “Tom” || “Mike”’ will throw an error in a language like Go, because Go says you have to explicitly compare your variables/literals to something. Yet C won’t throw an error because C only cares if the condition is some variation of zero (eg NULL) or non-zero value.

  • @tunak79
    @tunak79 Рік тому

    Thanks!

    • @b001
      @b001  Рік тому

      Wow! Thank you so much!!

  • @soumilbinhani8803
    @soumilbinhani8803 2 роки тому +4

    Rather than using a list to check because it is processing heavy you can use
    If name=='bob' or name=='tom' or name=='mike':
    This is not processing heavy

    • @schlopping
      @schlopping 2 роки тому +8

      generally name in [...names] is prefered, as proformance loss here is negligable. He's not checking for millions of names lol

  • @mijoizagas3747
    @mijoizagas3747 Рік тому

    Cracking good mate. Keep on with the videos.

  • @kharitrafan
    @kharitrafan 2 роки тому +6

    poor Chris😢

  • @Don.of.
    @Don.of. Рік тому

    Great video! I just learned about lists, and recently did the lessons on bools, and this was fun to follow along with 😊

  • @NathanHedglin
    @NathanHedglin 2 роки тому +5

    This is why I code in real programming languages.

    • @ihtasham9237
      @ihtasham9237 2 роки тому +7

      Its funny you say that actually because the equivalent of this in other languages will give you the same result💀

  • @kos256
    @kos256 Рік тому

    You're a life saver, I've always did:
    if value == 'a' or value == 'b' or value == 'c':

  • @purplehat8900
    @purplehat8900 2 роки тому +4

    Congrats on discovering the most basic things in programming: conditions!

  • @izerath001
    @izerath001 Рік тому +1

    Fking THANK YOU! Just getting started with Python and programming and this was driving me nuts. Here, have a cookie.

  • @m.debilus8419
    @m.debilus8419 Рік тому

    Saw the problem right away but didn't thoughy of this answer, even knowing the prob you still learn new and efficient ways to do it and that's cool

  • @FirstLast-gk6lg
    @FirstLast-gk6lg Рік тому

    The intersection between logic and syntax is what makes me realize i don't think coding is meant for me

  • @rojjst
    @rojjst 8 місяців тому

    Ohh boy!! What a timing your short popped up

  • @mikuculus3720
    @mikuculus3720 Рік тому

    Literally didn’t know that list thing that’s helllla useful 😊

  • @kag2576
    @kag2576 8 місяців тому

    I've just started learning Python and I keep making this mistake. Glad to see that's why it does it the way it does, in retrospect it makes sense it evaluates the other two as true

  • @avrohomhousman5958
    @avrohomhousman5958 Рік тому +1

    Anyone else think you shouldn't be able to implicitly convert an object to a boolean

  • @MaxProgramming
    @MaxProgramming 2 роки тому

    I knew that output but dude that's a perfect example of showing where people mess up!

  • @crimsondragon2677
    @crimsondragon2677 Рік тому +2

    The second way is better because you can update the list during runtime.

  • @FighterMageCleric
    @FighterMageCleric 2 роки тому

    "Access Granted" looks like some order of operations shenanigans happening in the conditional.

  • @MrAqbos
    @MrAqbos Рік тому

    I think in this situation you should use cortege because list grab more memory. You don't need to append or remove values from list. So cortege is nice opportunity.

  • @josgibbons6777
    @josgibbons6777 2 роки тому +1

    If you're going to use those names repeatedly, make them a set (or a dict if you need to map them to something) rather than a list, so the check time is O(1), not O(n).

  • @hafidhrendyanto2690
    @hafidhrendyanto2690 2 роки тому +1

    it is by design guys, theres a lot of use case in which this is actually the prefered behavior

    • @maxclifford937
      @maxclifford937 Рік тому

      A string being a same as true is not great design. Sure it might make somethings feel simpler but it's a massive footgun you generally don't get in statically typed languages.

  • @nicolasf-22
    @nicolasf-22 Рік тому +1

    I like this can of video where there is a little problem and I have to understand why the code do that. I'm beginning to learn python, so it's a good way to avoid mistake next time I use if

  • @insoft_uk
    @insoft_uk 11 місяців тому +1

    It’s obvious, tho I guess new programmers who started with Python may make that mistake but not C programmers, || && guess helps know these are getting interpreted separately

  • @_Yulico_
    @_Yulico_ 2 роки тому +1

    fun fact, its the same thing for every lenguage, you cant do "if a==1 or 2 or 3" its always "if a==1 or a==2 or a==3"

  • @rit056
    @rit056 2 роки тому

    Finally, something python related short that I can understand.
    I'm a beginner lol.

  • @Md915
    @Md915 Рік тому +1

    I lovw the way you explained this, at first I was wondering why there were 2 equal signs there, but then I saw the whole vid and was like "Oh yeah that makes more sense" (I'm new to Python, not to programming (at all))

  • @schlopping
    @schlopping 2 роки тому +2

    I'm seeing a lot of comments about processing power that really do not at all apply here. We are checking for 3 values, there is no need to obfuscate this code with optimisations. And for anyone that's trying to check for billions of names, I'd recommend another language lol

    • @esfera2181
      @esfera2181 2 роки тому

      What language

    • @schlopping
      @schlopping 2 роки тому +1

      ​@@esfera2181 For performance? Try Rust or C

  • @ScarecrowKnights
    @ScarecrowKnights Рік тому

    strings having truth values is such a nightmare lol

  • @MrDoom159
    @MrDoom159 2 роки тому

    The thing is, this quirk appears in other languages, but with a slight change of conventions. Java for example allows objects without any comparison to act as boolean values in conditional statements, so the standard is that null objects are always considered false. That's how I could guess

  • @satvikrajput847
    @satvikrajput847 Рік тому +1

    Me : if name in ('Bob','Tom','Mike'): 😅

  • @azareii
    @azareii 2 роки тому +1

    When the 'what will happen' question was asked, my thought was, "The logical answer is 'Access denied', but because he's asking, It'll probably be anything but that,"

  • @lucifermorningstarthelight4054
    @lucifermorningstarthelight4054 2 роки тому

    i was just making a little practice game and ran into that problem. thanks for the help man

  • @TabooRetka701
    @TabooRetka701 Рік тому

    As a python programmer, I almost cried when I saw your code

  • @creaminitalt
    @creaminitalt Рік тому

    I actually got to this problem before scraping my project😊

  • @gilarkt
    @gilarkt 11 місяців тому

    I love using array (list) in this case

  • @mrreddust
    @mrreddust 11 місяців тому

    My first thought is using any() methods but I guess this is more simple and accurate

  • @danielb.6643
    @danielb.6643 Рік тому

    I wouldn't do the list just because of the time complexity of checking if it's in the list. It's better to use a set or type out the individual comparison statements

  • @blueshell_dev
    @blueshell_dev Рік тому

    Add last names as a second variable, or possibly ID’s aswell

  • @djlclopez128
    @djlclopez128 Рік тому

    I didn't realize that, thanks!

  • @siliconfire
    @siliconfire 2 роки тому

    I thought i was the only one using synthwave 84 without the glowing effect

  • @Engiction
    @Engiction Рік тому

    Wow I'm actually surprised at myself I actually can read this code and understand this.
    But hey good work man keep it up

  • @WexyR
    @WexyR 2 роки тому +1

    No need to use a mutable list here.. use a tuple (unmutable), better performances on the long run

    • @WexyR
      @WexyR 2 роки тому

      @@farhanaditya2647 in this exemple, no it will not, but when you teach something, it's important not to teach also bad practices, even if it is a small mistake. Otherwise, beginners could get use to this bad practices.

    • @gigachad8810
      @gigachad8810 2 роки тому

      @@WexyR then you want to use a frozenset saved somewhere else outside of the if statement.

  • @dooterino
    @dooterino 10 місяців тому

    This is pretty much standard conditional syntax behavior across all languages, || (or)/ && (and) starts a new clause. The 'truthiness' of a value will vary from language to language, but string literals like that are pretty much always true.

  • @gavinkemp7920
    @gavinkemp7920 Рік тому

    It's a bit confusing but actually make sense when you take into account wanting empty value to evaluate to false.
    The other on "False" or Boolean("False") are both evaluated as True.

  • @cognomenn
    @cognomenn 2 роки тому

    you can also use set, because item in set() is O(1) most of the time, but same with list is O(n)

  • @mostordinaryexistence
    @mostordinaryexistence 2 роки тому

    Everytime I saw basic coding clips I feel like to challenge, but this is really satisfying
    Maybe because of his voice

  • @Dhanush3240
    @Dhanush3240 Рік тому

    Change the operator to and then the if statement will be false and check the else block btw i like your python shorts videos helping to practice myself

  • @ИмяФамилия-з3ш4п

    I like your video, you have very good content!

  • @senkolua
    @senkolua 2 роки тому +1

    you can make a list variable so you dont have to type [name1, name2, name3] all the time

  • @mewhenthetherealone
    @mewhenthetherealone 2 роки тому

    i got fooled 💀
    i love your vids

  • @engine_man
    @engine_man Рік тому +1

    For someone who doesn’t code in python my first instinct is to assume the first one is valid syntax.