I'm trying to assign a variable to a function call that simply capitalizes several paragraphs I got in a file, but the function call itself doesn't let me assign the variable, the error is Can't assign to function call
def text():
with open("par.txt", "r") as pa:
lines = pa.read()
context=lines.split("/n")
str_para=''.join(context)
x=str_para.split('\n')
for i in range(len(x)):
words =''.join(x[i]).capitalize(),end='\n'
return words
texts()
when I only use print(''.join(x[i]).capitalize(),end='\\n')
, it works fine, but i get the error once i assign the variable, how could i make this work?
Welcome to SO. Are you aware there is an indentation missing below the with statement? Might just be a formatting error of SO.
Try if that does what you want:
words = ''
for i in range(len(x)):
words +=''.join(x[i]).capitalize() + '\n\n\n'
return words
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.