1樓:wq yang
不一樣"1+2" => "1+2"
str(1+2) => "3"
2樓:大U哥
str() 不是字串的構造方法哦,而是 python 的乙個內建函式。看文件 2. Built-in Functions
Return a string containing a nicely printable representation of an object. For strings, this returns the string itself.
你可以簡單理解為,str() 函式的作用是將傳入物件轉換成字串,這也是 str() 存在的意義:
>>> str(1)
'1'>>> str(3.14)
'3.14'
>>> str('Hello')
'Hello'只不過恰好傳入字串就返回字串本身。至於每個物件被傳入 str() 函式返回什麼,通過實現物件的 __str__ 來控制,3. Data model :
object.__str__(self)
Called by the str() built-in function and by the print statement to compute the 「informal」 string representation of an object.
Python輸出啥時候加單引號啥時候不加單引號,我現在就知道數字不用,字母需要?
未來機器程式設計 樓主是不是迷惑 quotation mark 引號 存在的意義是什麼?它什麼時候要,什麼時候不要?在正式回答 quotation mark 引號 是什麼什麼時候用之前,我想多回答一些你可能存在的疑問 python裡單引號和雙引號的本質區別是什麼?其實在語言技術層面,單引號和雙引號沒...
python 單引號中怎麼引用變數 ?
黃哥 用字串格式化,前面佔坑,後面變數去填坑。format a b c a,b,c format a b c 2.7 only a,b,c format a b c c,b,a format abc unpacking argument sequence c,b,a format abra cad ...
為什麼教材裡寫左傾加引號 左 傾,右傾不加引號? 比如,總結了「左」傾和右傾錯誤
阿爾茲海默症患者 因為我們官方話語體系裡是自居左派的。左 打了引號,是左派都覺得它左,左的過頭,是不符合當前歷史階段發展要求的,是錯誤的。 金山不怕火煉 高中時我也問過歷史老師這個問題哈哈,後來自己想到是這樣的 首先是引號有一種用法是表否定,就是說被放在引號裡面後表達的不再是它的字面意思 然後是在政...