The first one is common in beginner code. I wouldn't call it outright useless, but more indicative of inexperience. The rest I admit I haven't seen much at all lol
re.liable
What is logic behind this syntax:
" is_true: bool = True " ??
yashbanait...
The "if x == True" can be useful to emphasize that the variable is a bool, not just a non-null value.
Ignas_
try:
pass
except:
pass
finally:
pass
teo
Here's a fancy one:
while 0: print("<sample text>")
print("Useless!")
idontwantanamethx
The first one should be written as print(True)
smarf
for _ in range(1):
print("How about this!!")
break
earthk
In the first example, simplifying changes the semantics. If the variable contains neither True not False, then neither line would be printed.
I find printing null is actually pretty useful for when debugging and I want to put a breakpoint in a tricky place without changing the functionality of the code
cavhaunch
I went through to shocked and angry and laugh at the same time
zapp
I’m going to fill my code with these and just confuse my students. Thanks for these
ovi_snipes
I found printing an empty string useful in one situation in Java. My friend had some code that didn't work properly and asked what's wrong with it. It looked like some code in a loop want executed do I asked him to add a print next to it to see if the execution enters the loop and the code started working, but without it, it didn't. I even tried running it on my computer with different version of Java and it behaved the same. Adding a breakpoint there also made it work. He ended up printing an empty string and adding a comment that it's necessary for the program to work. Fortunately it wasn't production code
PanDiaxik
"while true:
while false:
"
ItsCOMMANDer_
The first one is legitimately good advise tho, the other ones are just trolling. There is no way someone would write code like that, ever, because there is no logical pattern you can think in which would ever lead you to that code, unless you specifically wanted to write that exact piece of code just for the sake of writing that exact piece of code.
avananana
If you ever actually see someone doing 2-5 thinking it's proper production code, you should advise them to change career paths.
Other than the if-else, I've never seen anyone do the other 4 except as proof of concept as the what "break", "range", and "del" do along formatting the "print" output, so they're not useless in those contexts.
grant
for the first one get rid of the if statement entirely and just do print(is_true)…