亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SyntaxError:語法無效(Python 3.2)

SyntaxError:語法無效(Python 3.2)

料青山看我應如是 2021-03-22 17:23:18
我有一個函數,它將在字符串元組中插入空格,以便所有字符串的len相等。我還有一個函數,可以處理字符串元組和一些格式化信息,并將它們組合為一個字符串元組#code for equal string lengthdef insertSpace(self,content):    max = 0    for string in content:        temp = len(string)        if temp > max:            max=temp    retstring = ("",)    for string in content:         retstring = retstring + ("&nbsp;"*(max - len(string)+1,)    return self.combine(retstring,content,bold=False,newline=False)#code for combinedef combine(self,leftside,rightside,bold=False,newline=False):    if bold is True:        bold = '<B>'        boldend = '</B>'    else:        bold = ''        boldend = ''    if newline is True:        newlinechar = '<br>'    else:        newlinechar = ''    return tuple((bold +"{0}"+boldend+"{1}"+newlinechar).format(x,y) for x,y in zip(leftside,rightside))執行此腳本會導致File "mypythonfile.py", line 108return self.combine(retstring,content,bold=False,newline=False)     ^SyntaxError: invalid syntax我試圖將值存儲在變量中,但沒有任何改變。大概有點簡單,但我看不到。
查看完整描述

2 回答

?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

您錯過了)此行的結束語:


retstring = retstring + ("&nbsp;"*(max - len(string)+1,))

                                                        ^ 

                                                        | 

編輯:在您的代碼:


>>> 'retstring = retstring + ("&nbsp;"*(max - len(string)+1,)'.count("(")

3

>>> 'retstring = retstring + ("&nbsp;"*(max - len(string)+1,)'.count(")")

2


查看完整回答
反對 回復 2021-03-23
  • 2 回答
  • 0 關注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號