Answer the question
In order to leave comments, you need to log in
Why doesn't the first character change?
Good evening. I'm learning Python, I have code:
def test_funct(*args):
args_ = []
for i in range(len(args)):
if i == 0:
args_.append([str(elem.lower().replace(elem[0], elem[0].upper(), 1)) for elem in (str(args[i]).split())])
return args_
print (test_funct("Ya LOMAL steklo"))
Answer the question
In order to leave comments, you need to log in
Why not really break it down? At you even more than 80 characters the line turns out. It's not pep8 anymore, it's hard to read - and all that.
Well, as for the question. It turns out that replace takes the first character from the source string, and then looks for it in the one in which all the characters have been converted to lowercase and, of course, does not find it there in the first two cases.
Add lower to the first argument of replace
or use slicing altogether,
and Python has a built-in title() method for strings that does pretty much the same thing.
Breaking your main line into several simpler and more understandable ones and using a debugger/output intermediate results should help.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question