#傳統寫法
print("Line1")
x=1+1
print("Line2")
first_name=input('Please input first name!')
last_name=input('Please input Last_name!')
#capitalize將字串開頭轉大寫其它轉小寫
print(first_name.capitalize() + ' ' + last_name.capitalize())
#output 字串物件 ,利用output物件,簡化print字串寫法,程式碼較簡潔
output='My name is '+first_name + last_name
print(output)
output='My name is {} {}'.format(first_name,last_name) #{}搭配 format語法..有順序性
print(output)
output='My name is {0}_{1}'.format(first_name,last_name)#{0}編號由0開始,有順序性
print(output)
output='My name is {1}_{0}'.format(first_name,last_name)#{0}編號由0開始,有順序性
print(output)
output=f'My name is {first_name} {last_name}' #此寫法僅支援python 3,f關鍵字表示format
print(output)
執行結果.....
Line1
Line2
Please input first name!miller
Please input Last_name!wang
Miller Wang
My name is millerwang
My name is miller wang
My name is miller_wang
My name is wang_miller My name is miller wang
My name is wang_miller My name is miller wang