Program Language/Python

(python) bad operand type for unary +: 'str'

야곰야곰+책벌레 2023. 11. 27. 11:55
728x90
반응형
news_html = ""
for i in range(len(df_news_final)) :
    news_html = news_html + "<div><p><a href ='\
    " + str(df_news_final.loc[i, '원문주소']) + "'>\
    " + str(df_news_final.loc[i, '뉴스제목']) + "</a>\
    " + str(df_news_final.loc[i, '매체']) + " \
    " + str(df_news_final.loc[i, '등록일']) + "</p></div>"

python 3에서

final_sentence="""Pulled
"""+stock+""".""" 
print (final_sentence)

이건 동작하지만, 

final_sentence="""Pulled"""
+stock+""".""" 
print (final_sentence)

는 동작하지 않는다.

아마 operator 정의 문제인 듯하다.

아래와 같이 하면 잘 된다.

 

728x90
반응형