1.兩個字串放在一起會自動合并
"Let's say " '"Hello, world!"' --->'Let/'s say "Hello, world!"'
但是兩個字串變數放在一起中間要加“+”號才會合并
2.str與repr
str會將變數轉化成某種使用者能夠理解的String方式,如
print str(10000L) --->10000
#str(object) -- Converts a value to a string
repr會將變數轉化為Python的合法變數
print repr(10000L) --->10000L
另外repr(x)='x'
#repr(object) -- Returns a string representation of a value
3.input與raw_input
name = input("What is your name? ")斷行符號繼續
What is your name? Gumby
會出錯,因為input會假設你輸入的是有效Python變數,而此處Gumby未定義。改為
What is your name? 'Gumby'則成功
#input(prompt) -- Gets input from the user
name = raw_input("What is your name? ")斷行符號繼續
What is your name? Gumby 則不會報錯,因為raw_input會認為輸入的均為String
#raw_input(prompt) -- Gets input from the user, as a string
4.'''與r與u
'''長字串''' 中間可以分行,可以任意用'、"
r首碼為Raw String, 'Hello /nthyU!'會分行,而r'Hello /nthyU!'就忠實於WhatYouSeeIsWhatYouGet,
u首碼為Unicode String,每個字元用16Bit。