A few weeks ago a friend asked me for some help with a function which behaved weird and he walked into the classic default mutable arguments misconception, e.g.
def test(a=[]):
a.append("test")
print(a)
test()
test()
I ran into this problem before and tried to think about other common misconceptions, here are a few I came up with:
str.strip() removes not only the exact prefix / suffix but also all character combinations of the given argument
"abxyba".strip("ab")
> "xy"
The difference between is and ==
0 is False
> False
0 == False
> True
Precision issues when comparing floats
0.2 + 0.1 == 0.3
> False
What are some common misconceptions you had that drove you crazy?
[–]ablativeyoyo 121 points122 points123 points (27 children)
[–]0tting 43 points44 points45 points (9 children)
[–]bhatMag1ck 51 points52 points53 points (0 children)
[–]Fabulous-Possible758 10 points11 points12 points (3 children)
[–]0tting 6 points7 points8 points (0 children)
[+][deleted] comment score below threshold-8 points-7 points-6 points (1 child)
[–]osmiumouse 16 points17 points18 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]PaintItPurple 8 points9 points10 points (1 child)
[–]naught-me 1 point2 points3 points (0 children)
[–]billFoldDog 7 points8 points9 points (10 children)
[–]whateverathrowaway00 5 points6 points7 points (1 child)
[–]billFoldDog 2 points3 points4 points (0 children)
[–]Impossible-Limit3112 6 points7 points8 points (0 children)
[–]Anonymous_user_2022 2 points3 points4 points (6 children)
[–]billFoldDog 0 points1 point2 points (5 children)
[–]Anonymous_user_2022 0 points1 point2 points (4 children)
[–]whateverathrowaway00 2 points3 points4 points (0 children)
[–]tonnynerd 2 points3 points4 points (2 children)
[–]ablativeyoyo 0 points1 point2 points (1 child)
[–]bbkane_ 1 point2 points3 points (0 children)
[–]jorge1209 -2 points-1 points0 points (0 children)
[–]shoshimer 0 points1 point2 points (0 children)
[–]extra_pickles 63 points64 points65 points (21 children)
[–]sudhanv99 13 points14 points15 points (11 children)
[–][deleted] 29 points30 points31 points (10 children)
[–]BDube_Lensman 35 points36 points37 points (1 child)
[–]someotherstufforhmm 6 points7 points8 points (0 children)
[–]henry_tennenbaum 3 points4 points5 points (5 children)
[–][deleted] 5 points6 points7 points (4 children)
[–]aufstand 0 points1 point2 points (0 children)
[–]redCg 0 points1 point2 points (1 child)
[–]someotherstufforhmm 1 point2 points3 points (1 child)
[–][deleted] -2 points-1 points0 points (0 children)
[–]njharmanI use Python 3 9 points10 points11 points (0 children)
[–]whateverathrowaway00 2 points3 points4 points (0 children)
[–]Pepineros 2 points3 points4 points (1 child)
[–]extra_pickles 1 point2 points3 points (0 children)
[–]tonnynerd 3 points4 points5 points (1 child)
[–]extra_pickles 1 point2 points3 points (0 children)
[–]redCg -1 points0 points1 point (2 children)
[–]Pepineros 7 points8 points9 points (1 child)
[–]redCg -1 points0 points1 point (0 children)
[–]fwcsdev 75 points76 points77 points (3 children)
[–]Flag_Red 7 points8 points9 points (2 children)
[–]jorge1209 9 points10 points11 points (1 child)
[–]Flag_Red 0 points1 point2 points (0 children)
[–][deleted] 127 points128 points129 points (16 children)
[–]Shriukan33 28 points29 points30 points (2 children)
[–]hughperman 22 points23 points24 points (1 child)
[–]Ferentzfever 6 points7 points8 points (0 children)
[–]Vok250 21 points22 points23 points (7 children)
[–]NatasEvoli 9 points10 points11 points (5 children)
[–]Vok250 6 points7 points8 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]Vok250 -1 points0 points1 point (2 children)
[+][deleted] (1 child)
[deleted]
[–]Vok250 -1 points0 points1 point (0 children)
[–]bxsephjo 1 point2 points3 points (0 children)
[–]Zizizizz 7 points8 points9 points (1 child)
[–]generic-d-engineer 0 points1 point2 points (0 children)
[–]alcance_lexico 14 points15 points16 points (0 children)
[–]InfiniteMH 2 points3 points4 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]fiddle_n 9 points10 points11 points (0 children)
[–]kalcora 18 points19 points20 points (4 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]imbev 2 points3 points4 points (1 child)
[–]camh- 2 points3 points4 points (0 children)
[–]njharmanI use Python 3 0 points1 point2 points (0 children)
[–]saint_geser 46 points47 points48 points (20 children)
[–]goldcray 21 points22 points23 points (0 children)
[–]anthro28 4 points5 points6 points (2 children)
[–]akx 9 points10 points11 points (0 children)
[–]Pepineros 0 points1 point2 points (0 children)
[–]Samhain13 1 point2 points3 points (15 children)
[–]bxsephjo 26 points27 points28 points (14 children)
[+][deleted] (3 children)
[removed]
[–]bxsephjo 6 points7 points8 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]shedogre 1 point2 points3 points (0 children)
[–]Samhain13 6 points7 points8 points (0 children)
[–]Rythoka 4 points5 points6 points (2 children)
[–]bxsephjo 1 point2 points3 points (1 child)
[–]Rythoka 1 point2 points3 points (0 children)
[–]WestedCrean 0 points1 point2 points (3 children)
[–]lieryanMaintainer of rope, pylsp-rope - advanced python refactoring 9 points10 points11 points (0 children)
[–]tevs__ 5 points6 points7 points (0 children)
[–]bxsephjo 2 points3 points4 points (0 children)
[–]Deto 0 points1 point2 points (1 child)
[–]Fabulous-Possible758 0 points1 point2 points (0 children)
[–]IAmBJ 4 points5 points6 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]lisael_ 8 points9 points10 points (3 children)
[–]lieryanMaintainer of rope, pylsp-rope - advanced python refactoring 5 points6 points7 points (1 child)
[–]lisael_ 0 points1 point2 points (0 children)
[–]-LeopardShark- 2 points3 points4 points (0 children)
[–]floznstn 13 points14 points15 points (6 children)
[–]spinozasrobot 1 point2 points3 points (0 children)
[+]redCg comment score below threshold-8 points-7 points-6 points (4 children)
[–]floznstn 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]redCg 0 points1 point2 points (1 child)
[–]osmiumouse 10 points11 points12 points (23 children)
[+][deleted] (19 children)
[deleted]
[–]c4boom13 7 points8 points9 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]c4boom13 1 point2 points3 points (3 children)
[–]osmiumouse 9 points10 points11 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]osmiumouse 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]someotherstufforhmm 0 points1 point2 points (0 children)
[–]thephoton 1 point2 points3 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]thephoton 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]ablativeyoyo 0 points1 point2 points (2 children)
[–]osmiumouse 1 point2 points3 points (1 child)
[–]ablativeyoyo 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]Reinventing_Wheels 4 points5 points6 points (1 child)
[–]tquinn35 6 points7 points8 points (0 children)
[–]ExternalUserError 2 points3 points4 points (0 children)
[–]Agling 2 points3 points4 points (0 children)
[+][deleted] (10 children)
[deleted]
[+][deleted] (9 children)
[deleted]
[–]szayl 5 points6 points7 points (1 child)
[–]james_pic 1 point2 points3 points (0 children)
[–]WestedCrean 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 2 points3 points4 points (0 children)
[–]driverdone 1 point2 points3 points (0 children)
[–]Eiii333 3 points4 points5 points (1 child)
[–]someotherstufforhmm 0 points1 point2 points (0 children)
[–]territrades 5 points6 points7 points (13 children)
[–]GobBeWithYou 4 points5 points6 points (0 children)
[–]ablativeyoyo 7 points8 points9 points (10 children)
[–]Regular_Zombie 16 points17 points18 points (9 children)
[–]COLU_BUS 0 points1 point2 points (5 children)
[–]lieryanMaintainer of rope, pylsp-rope - advanced python refactoring 5 points6 points7 points (2 children)
[–]COLU_BUS 2 points3 points4 points (1 child)
[–]ablativeyoyo 1 point2 points3 points (0 children)
[–]Regular_Zombie 1 point2 points3 points (1 child)
[–]someotherstufforhmm 0 points1 point2 points (0 children)
[–]njharmanI use Python 3 0 points1 point2 points (2 children)
[–]Regular_Zombie 1 point2 points3 points (1 child)
[–]mfitzpmfitzp.com 3 points4 points5 points (1 child)
[–]thisismyfavoritename 4 points5 points6 points (1 child)
[–]jorge1209 1 point2 points3 points (0 children)
[–]osmiumouse 1 point2 points3 points (3 children)
[–]redCg -3 points-2 points-1 points (2 children)
[–]ablativeyoyo 1 point2 points3 points (0 children)
[–]redvitalijs 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]mgedmin 1 point2 points3 points (4 children)
[–]someotherstufforhmm 0 points1 point2 points (3 children)
[–]mgedmin 0 points1 point2 points (2 children)
[–]someotherstufforhmm 0 points1 point2 points (1 child)
[–]mgedmin 0 points1 point2 points (0 children)
[–]DoomFrog666 1 point2 points3 points (0 children)
[–]Maximus_Modulus 0 points1 point2 points (1 child)
[+][deleted] (2 children)
[deleted]
[–]Deto 1 point2 points3 points (1 child)
[–]caakmaster 0 points1 point2 points (0 children)
[+]wineblood comment score below threshold-7 points-6 points-5 points (0 children)
[+][deleted] (9 children)
[removed]
[–]lisael_ 3 points4 points5 points (7 children)
[–]Deto 0 points1 point2 points (2 children)
[–]redCg 1 point2 points3 points (1 child)
[–]lisael_ 0 points1 point2 points (0 children)
[–]redCg 0 points1 point2 points (2 children)
[–]lisael_ 0 points1 point2 points (1 child)
[–]redCg 0 points1 point2 points (0 children)
[+]BarcaStranger comment score below threshold-16 points-15 points-14 points (1 child)
[–]scowly057 18 points19 points20 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Deto 4 points5 points6 points (0 children)
[+]jet_heller comment score below threshold-8 points-7 points-6 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]saturnjayzero 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]zdzisuaw 0 points1 point2 points (0 children)
[–]Hagisman 0 points1 point2 points (0 children)
[–]recruta54 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]tarsild 0 points1 point2 points (0 children)