簡體   English   中英

格式化字符串地獄 - Python

[英]Formatted string hell - Python

x = f'{1}{2}{3}'

a = "one"
b = "two"
c = "three"

#I want to print "onetwothree"

我什至不知道如何解釋這個問題,每次我開始在谷歌中輸入任何內容時,我都愣住了。 還沒有嘗試任何東西,因為我什至不知道從哪里開始。 幫助。

您可以在 f 字符串的括號內插入變量的名稱。

a = "one"
b = "two"
c = "three"

print(f'{a}{b}{c}')
>>> onetwothree

將變量名稱放入 f 字符串中。

print(f"{a}{b}{c}")
x = f'{1}{2}{3}'

a = "one"
b = "two"
c = "three"

#I want to print "onetwothree"
print(f"{a}{b}{c}")

在此處輸入圖像描述

說明:對於每個變量x ,您填寫{x} 對於 python 3,如果要打印項目,請使用print(item) function。

print() function 將指定的消息打印到屏幕或其他標准 output 設備。 消息可以是字符串,也可以是其他任何 object,object 會在寫入屏幕之前轉換為字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM