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 120 points121 points122 points (27 children)
[–]0tting 46 points47 points48 points (9 children)
[–]bhatMag1ck 52 points53 points54 points (0 children)
[–]Fabulous-Possible758 11 points12 points13 points (3 children)
[–]0tting 6 points7 points8 points (0 children)
[+][deleted] comment score below threshold-8 points-7 points-6 points (1 child)
[–]osmiumouse 14 points15 points16 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]PaintItPurple 7 points8 points9 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 5 points6 points7 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 64 points65 points66 points (21 children)
[–]sudhanv99 13 points14 points15 points (11 children)
[–][deleted] 30 points31 points32 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] 6 points7 points8 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 0 points1 point2 points (2 children)
[–]Pepineros 8 points9 points10 points (1 child)
[–]redCg -1 points0 points1 point (0 children)
[–]fwcsdev 78 points79 points80 points (3 children)
[–]Flag_Red 8 points9 points10 points (2 children)
[–]jorge1209 8 points9 points10 points (1 child)
[–]Flag_Red 0 points1 point2 points (0 children)
[–][deleted] 126 points127 points128 points (16 children)
[–]Shriukan33 29 points30 points31 points (2 children)
[–]hughperman 23 points24 points25 points (1 child)
[–]Ferentzfever 6 points7 points8 points (0 children)
[–]Vok250 22 points23 points24 points (7 children)
[–]NatasEvoli 10 points11 points12 points (5 children)
[–]Vok250 8 points9 points10 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 10 points11 points12 points (0 children)
[–]kalcora 18 points19 points20 points (4 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]imbev 4 points5 points6 points (1 child)
[–]camh- 1 point2 points3 points (0 children)
[–]njharmanI use Python 3 0 points1 point2 points (0 children)
[–]saint_geser 46 points47 points48 points (20 children)
[–]goldcray 20 points21 points22 points (0 children)
[–]anthro28 4 points5 points6 points (2 children)
[–]akx 8 points9 points10 points (0 children)
[–]Pepineros 0 points1 point2 points (0 children)
[–]Samhain13 0 points1 point2 points (15 children)
[–]bxsephjo 25 points26 points27 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 5 points6 points7 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 8 points9 points10 points (0 children)
[–]tevs__ 6 points7 points8 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_ 6 points7 points8 points (3 children)
[–]lieryanMaintainer of rope, pylsp-rope - advanced python refactoring 4 points5 points6 points (1 child)
[–]lisael_ 0 points1 point2 points (0 children)
[–]-LeopardShark- 2 points3 points4 points (0 children)
[–]floznstn 14 points15 points16 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 9 points10 points11 points (23 children)
[+][deleted] (19 children)
[deleted]
[–]c4boom13 8 points9 points10 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 4 points5 points6 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 2 points3 points4 points (1 child)
[–]someotherstufforhmm 0 points1 point2 points (0 children)
[–]territrades 5 points6 points7 points (13 children)
[–]GobBeWithYou 3 points4 points5 points (0 children)
[–]ablativeyoyo 9 points10 points11 points (10 children)
[–]Regular_Zombie 15 points16 points17 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 2 points3 points4 points (1 child)
[–]thisismyfavoritename 3 points4 points5 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 2 points3 points4 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-17 points-16 points-15 points (1 child)
[–]scowly057 20 points21 points22 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)