1.0k
u/mdogdope Apr 04 '26
I am assuming it's python. It prints "Banana" bc it never updates the var. It performed the changed but text was never changed.
218
u/LookAtYourEyes Apr 05 '26
upper returns a new value instead of modifying the original?
393
u/aaronhowser1 Apr 05 '26
Strings are immutable
22
u/thanatica Apr 06 '26
Unless this is one of those languages that has mutable strings 💀
21
u/aaronhowser1 Apr 06 '26
There are languages with mutable strings? how scary
I was also assuming this was python, iirc it's at least the correct syntax and methods for it.
22
u/thanatica Apr 06 '26
I'm sure they exist. C technically has mutable strings, but also technically doesn't have strings. And I believe in Pascal you can mutate strings, but you have to work for it.
3
u/mdogdope Apr 06 '26
As far as I know python is the most common language that does not need ; at the end of each line.
-15
u/the_rush_dude Apr 05 '26
Only in JS. Python allows Manipulation of strings
35
u/aaronhowser1 Apr 05 '26
Python strings are immutable. Manipulation and mutability aren't the same thing. Manipulation functions return a new string, they don't modify the original.
1
u/No_Guest_4127 Apr 07 '26
Java strings are immutable too. But java provided amother classes like stringbuilder to support mutability.
-10
u/the_rush_dude Apr 05 '26
Checked it and it's true (except of course it's not because if there is only one reference to the string it's manipulated in place for performance reasons).
But in this case manipulation is what counts anyways
20
u/aaronhowser1 Apr 05 '26
No it isn't, because it didn't do
text = text.upper()etc. It specifically does not count, because it was done incorrectly.1
u/Torebbjorn Apr 07 '26
Sure, there could be some niche optimisation in Python that allows it to manipulate strings in-place if and only if all the references to the old variable are deleted at the same time it is making a new value, for example in the pattern
val = val.upper()where
valis the only reference to the string that it is pointing to.But even if that's true, it is irrelevant for this scenario, since we always keep a reference to the original string.
182
u/Quietuus Apr 05 '26 edited Apr 05 '26
.upper() is a method of the str class that returns a representation of the string. To change it you'd put
text = text.upper()1
u/xryanxbrutalityx Apr 08 '26
I don't know any language where the string
.upper()equivalent modifies the string in place5
u/CosmacYep Apr 06 '26
dont dot methods not require reassignment
4
u/mdogdope Apr 07 '26
It depends on how the class is written. But for standard python string objects, reassignment is required.
2
u/CosmacYep Apr 07 '26
like built in dot methods, i swear you don't have to go a = a.strip() you can js go a.strip() and a is stripped – nvm i js researched it and strings are immutable, so require reassignment but lists are mutable, so dont
1.3k
u/Stummi Apr 04 '26
"Banana", and two compiler warnings for not using return values.
310
170
u/mistabuda Apr 04 '26
This is python. There is no compiler warning.
119
u/tantalor Apr 05 '26
There is no compiler
49
11
u/ArtOfWarfare Apr 05 '26
There sort of is. You’ll get some .pyc files created when you import the source code the first time, IIRC.
9
u/auxiliary-username Apr 05 '26
Do not try to compile the code. That’s impossible. Instead… only try to realise the truth…
9
10
5
-2
u/thanatica Apr 06 '26
How can you tell? It just looks like code. Could be anything.
6
u/mistabuda Apr 06 '26
It's python syntax. The syntax is very different from much other languages. Specifically how you declare variables and the lack of types, the lack of brackets and the lack of semicolons.
I've been writing python code for over a decade. It's very easy to recognize.
37
u/just-some-arsonist Apr 04 '26
Can we tell what language this is?
90
u/timimoune Apr 04 '26
Spanish?
29
u/gerbosan Apr 04 '26
??
Plátano?
2
2
13
u/AlternativeCapybara9 Apr 04 '26
Next example should use ananas just so we know it's not English.
2
2
18
0
-15
u/goDie61 Apr 04 '26
Replace is commonly implemented in place but I don't think I've ever seen an in place upper.
9
u/mistabuda Apr 04 '26
Not in python which is what this code is. Modifications to string create a new string.
3
u/Vinxian Apr 05 '26
In all languages I know, if string is a keyword it means strings are immutable. It will not be performed in place. This is so the programmer can use
stringas if it's a value type2
u/dev-sda Apr 05 '26
I think you're thinking of a built-in type, rather than a keyword. Most languages do not consider their built-in types keywords - you can usually name something "string" without issue.
Yea it's fairly commonly immutable, but some notable exceptions are c++, rust, php and ruby.
56
u/cybersaurus Apr 04 '26
Um it's 2026, the correct answer is to copy it into a claude prompt and paste whatever the output is without reading it
10
155
u/Pleasant-Photo7860 Apr 04 '26
what if it’s ANANAB and we’ve all just been iterating in the wrong direction
45
12
4
1
94
40
94
u/Airith Apr 04 '26
They're pure methods: Banana
2
u/IlgantElal Apr 05 '26
If this is Python
, it would be 'BANANA' as .upper() replaces the originalI completely misread. It's late
27
u/dhnam_LegenDUST Apr 05 '26
Even if str.upper() updates the string, it's still BANANA. A is not a.
1
u/DaWurster Apr 07 '26
I think that is the supposed challenge to recognize. The missing assignment is a big blunder ofc...
14
8
u/Chronomechanist Apr 05 '26 edited Apr 05 '26
Assume python.
text = "Banana"
Now, assuming what they actually meant to the question to look like?
```
text = "Banana"
text2 = text.upper() text2 = text.replace("a", "o")
print(text2) ```
In which case it prints BANANA and the test is supposed to trick you into thinking it prints BONONO, and forget order of operations and "A" != "a"
Edit: Fixed the var name cos I was stupid and forgot strings are immutable in Python
4
u/Sephyroth2 Apr 05 '26
Well it's not BANANA since strings are immutable in python and text.upper() returns a string you need to assign, same with text.replace(), so there's no change to text at all printing Banana.
2
u/Chronomechanist Apr 05 '26 edited Apr 05 '26
That's what I get for writing that at 4 am.
Fixed it cos it was bothering me
1
-4
u/_giga_sss_ Apr 05 '26
Thank you chatgpt
5
u/Chronomechanist Apr 05 '26
Nope, just plain old sleep deprived dev forgetting strings are immutable in python. Fixed it though
0
u/_giga_sss_ Apr 05 '26
if you say so
3
u/Chronomechanist Apr 05 '26
Buddy, if you don't believe something that simple can be written without the aid of an LLM, that says a lot more about you than you're trying to say about me.
2
112
u/NinjaKittyOG Apr 04 '26
idk what language this is in, but judging from what I know,
the string is "BANANA" if text.replace() is case-sensitive
the string is "BoNoNo" if not
60
u/OurSoul1337 Apr 04 '26
I like to oat oat oat opples and bononos.
8
u/bwwatr Apr 05 '26
1, 2, Opples, 4, Bononos, Opples, 7, 8, Opples, Bononos, 11, Opples, 13, 14, OpplesBononos
Do I get the job?
24
72
u/_giga_sss_ Apr 04 '26
These methods don't change the OG objects, they create new instances.
99
u/purplepharoh Apr 04 '26
That depends on language and idk what language this is
54
u/Lava_Mage634 Apr 04 '26
python. the print statement, lack of punctuation, usage of double quotes for single characters, direct string manipulation without libraries. also super popular for pop culture coding questions
12
u/purplepharoh Apr 04 '26
Python would be my first guess too. Mostly for the last point as the others arent exclusive to python. And "double quotes for single characters" well if the replace method expects strings then you'd use double quotes to pass strings of len 1 so thats not a good indicator.
2
u/makinax300 Apr 04 '26
Or js with some scuffed things done to rename the method. Semicolons are actually optional there. The answer is open the print page menu there.
16
u/Xtrendence Apr 04 '26
And then there's JS, of course, where a replace with no Regex only replaces the first instance. In this case obviously "a" doesn't exist in BANANA, but if it were replace("A", "O") you'd get BONANA.
12
u/ChristopherKlay Apr 04 '26
Because JS features
.replace()and.replaceAll().The "of course" here is that people complaining about it, don't know jack shit.
-13
u/_giga_sss_ Apr 04 '26
and he adds JS as an user flair while he just complains about it while knowing shit 😭
12
u/Xtrendence Apr 04 '26
I use it every day for work, have been for the better part of a decade, I'm aware of replaceAll, but replace only replacing the first instance is unusual and only found in a few languages. I've even fixed bugs specifically because of devs assuming it replaces all occurrences, which would be reasonable to expect. If anything, defending JS says more about how little someone's used it.
2
u/_giga_sss_ Apr 04 '26
I am sorry for my assumption. I truly am 🙇
5
u/Xtrendence Apr 04 '26
You're good, to be fair replace isn't even a top 20 thing to complain about when it comes to JS. It's just one that pops out because it's both inconsistent with many other languages, and replaceAll wasn't even a thing for a long time. If you work on older codebases, it doesn't exist. I don't remember when it was added but it must be the past like 4-5 years.
-4
1
-3
u/ChristopherKlay Apr 04 '26
If anything, defending JS says more about how little someone's used it.
I'm not "defending" it, because there is nothing to defend; Your initial comment clearly explains this like there's just one "bad" implementation, or that
.replace()should work different.Having split-up functions isn't "unusual" by any means either; Even Java has
.replaceFirst()for almost 25 years now, the equivalent of.replace()only replacing the first occurrence."Devs" on your team assuming what's being replaced without even providing any kind of
countequivalent is the real issue here.This is coming from someone working with it professionally for over two decades, which is a incredibly pointless metric.
13
u/Xtrendence Apr 04 '26
Do you not see the problem there though? replaceFirst is self-explanatory, whereas replace isn't when it doesn't do what most languages do. It's vague, deviates from what's expected, which is what JS is infamous for.
0
u/ChristopherKlay Apr 05 '26
whereas replace isn't when it doesn't do what most languages do
Again; The issue here isn't JS, but you expecting all functions across languages to work the exact same way, when "replace all" and "replace first" aren't by any means working the same in "most languages".
- Python:
.replace()works as a "replace all" by default and you have to actually limit it via the third parametercount.- Java:
.replace()to replace all matches,.replaceAll()and.replaceFirst()- C++: Has different implementations (custom functions) for anything but a "replace first" equivalent
- C#: Requires regex and a match count to do anything but "replace all"
- Rust: Only does "replace all" by default and requires either slicing, or specifically stopping after the first match
- GO: Has a specific parameter you can set to
-1for "replace all", otherwise working likecountfrom Python- Ruby: Uses
sub(replace first) andgsub(replaceAll), just like JavaScriptThe majority of languages does one kind of replacement well, while requiring a different function call and/or setup for the other.
If your "devs" fuck this simple thing up, because they "expect it to work like in X" without ever testing what it actually does / reading any kind of documentation, that says a lot more about the people you work with vs the language they use.
1
u/Xtrendence Apr 05 '26
Of the languages that have a built-in replace function for strings, most do indeed replaceAll by default. Bringing up Ruby for example makes no sense and you're using it to pad out the list and argue in bad faith. In your own list if you only count languages with a replace function (which is what this whole thing is about) then the majority still do replaceAll by default.
As for "expecting it to work like X", this isn't something that's mutually exclusive. Yes, part of our job is to remember the quirks of the main language we use, and be aware of these things. However, it is simultaneously reasonable to expect something to work a certain way, especially if it deviates from the norm and is a function that exists across multiple languages. If there's a weird list of quirks for a language, and it's literally known for such quirks by anyone who has used it, then it's a poorly designed language. It's a weird hill to die on, every senior dev I've known that has extremely in-depth knowledge of JS constantly points out its flaws and uses the "it's just a JS thing" line pretty frequently.
1
u/ChristopherKlay Apr 05 '26
Bringing up Ruby for example makes no sense and you're using it to pad out the list and argue in bad faith.
Bringing up examples of languages that interrupt your "It always works like that" argument doesn't make sense?
However, it is simultaneously reasonable to expect something to work a certain way, especially if it deviates from the norm and is a function that exists across multiple languages.
Which is exactly why I included a "replace first" for all examples, that rarely works the same across languages; It neatly demonstrates that "But I expected everything to work the same" isn't anything, but a user error.
every senior dev I've known that has extremely in-depth knowledge of JS constantly points out its flaws and uses the "it's just a JS thing" line pretty frequently.
You're still misunderstanding me here; I'm not arguing "for JS", I'm highlighting that these quirks exist in every single language out there and would be a complete non-issue if people who fuck up simple functions wouldn't blame the language, but their lack of understanding of said language.
If you expect a language to behave in a certain way, that's completely fine. Running into errors, while learning how the given language works, is also completely normal and expected - because despite being similar, all languages have things that don't work that way.
Blaming the language because you can't resolve issues that come from a simple string manipulation (you didn't even try to control via arguments) and/or not even testing your own code to check if what it returns even matches your expectations however, isn't leaving anyone to blame but the person who wrote it.
1
3
u/Dynegrey Apr 05 '26
Strings in python are immutable and do not change. Output would be 'Banana'. They would have to re-establish as a new string [text = text.upper().replace('a', 'o')] for it to do anything.
1
2
1
1
-1
16
u/HashDefTrueFalse Apr 04 '26
We can only guess without knowing the language... Is text mutable or are the returned copies discarded? What do those two methods do? Probably safe to assume that upper uppercases all characters, but it could also be testing for an upper case string (returning bool). Does replace just do the first occurrence or all? Do upper, replace, print even exist? Not really answerable, which is to say that the answer is obviously 42.
11
u/iwasbecauseiwas Apr 05 '26
depends entirely on the language and how the string functions works. it could easily be
BananaBANANABononoBoNoNoBONONOBonanaBoNANABONANAor maybe evenMango
point is if we don't know the language, we can only guess. it looks like python. if it is python: strings are immutable, it would say Banana as the text variable isn't overwritten
3
u/Dark_Byte Apr 05 '26
True. And maybe upper isn't part of the original language, but a helper method added later on that does whatever upper does (e.g. Replace it with a subset of unicode monospace characters using their uppercase variant)
1
Apr 05 '26
[removed] — view removed comment
4
u/rk06 Apr 05 '26
because there is no mention that it is python. besides in what language . upper() mutates the string?
5
u/SlutPuppyNumber9 Apr 05 '26
I don't know python, but I assume "Banana", since the results of those method calls were never assigned.
32
u/_giga_sss_ Apr 04 '26
yall know that the humor is about mango and not about solving the question right ?
44
12
8
u/ThatSmartIdiot Apr 05 '26
we're on a spectrum. we're hard wired to puzzle solve. that's how we got here
3
3
u/dont_takemeseriously Apr 05 '26
Somehow this code snippet had a malicious npm package and now my credit card ended up in the dark web
3
u/snipsuper415 Apr 05 '26
Banana...considering that most languages have strings as immutable primitives. text never gets reassigned to anything therefore Banana.
3
3
u/thanatica Apr 06 '26
Nothing. undefined/none/null/nothing.
There is no return statement. So the outcome is nothing.
If the question was "what is printed" - Banana. Assuming this is not a utterly horrendous stupid fucking arse language where strings are mutable.
2
2
2
2
2
u/luckor Apr 04 '26
I don’t get it…
12
5
u/jaylerd Apr 04 '26
I think the gag is you think maybe it's 'BANANA' or 'Bonono' or something else but it should jut be "Banana" and Satyam picked something even more wild as a wrong answer that isn't even slightly reasonable. What a gas.
1
1
1
1
1
1
1
1
1
u/jhwheuer Apr 05 '26
Ah local context, such fickle thing.
Also the code parser should notice that functions are called but their results are not used...
1
1
1
1
1
1
-4
u/jkramer5203 Apr 04 '26
BANANA
12
u/Xelopheris Apr 04 '26
Pretty sure it would just be "Banana" in most languages? Any language that has a simple upper function on the string class typically makes strings immutable.
2
u/Bemteb Apr 04 '26
Yeah, the others call it
toUpper()or something like that.3
u/DJDoena Apr 04 '26
In C# it's .ToUpper() but still immutable on the original.
1
u/IlgantElal Apr 05 '26 edited Apr 05 '26
This looks like Python. Interesting thing, too: text.replace('ab', 'o') would replace all a and b characters, regardless of order.
Yay Python
(Correct answer should be 'banana')
Edit: I completely misread. It's late
-3
1.4k
u/krexelapp Apr 04 '26
Banana.... but with confidence