Python入門之使用者互動

2021-10-12 06:31:11 字數 1265 閱讀 3277

?"input"會將使用者輸入的內容都轉化成字串型別

name =

input

("請輸入你的名字》"

)#輸入"shawn"

print

(name)

#shawn

passwd =

input

("請輸入密碼》"

)#"123"

print

(type

(passwd)

)#

?python2中"input"有兩種1.

"raw_input"

,等同於python3中的"input"2.

"input"

,需要使用者輸入乙個明確的資料型別,輸入的什麼型別就存成什麼型別

x =

1y =

2z =

3print

(x)#1

print(2

)#2print

(x,y,z)

#1,2,3

?"print"預設自帶"\n"

可以使用'end=""'來取消

?按照位置順序傳值,一一對應

msg =

"my name is %s"%(

'shawn'

)msg =

"my name is %s,my age is %s"%(

'shawn',22

)print

(msg)

?按照位置順序傳值

msg =

"my name is {}"

.format

('shawn'

)msg =

"my name is {},my age is {}"

.format

('shawn',22

)?通過索引取值

msg =

"my name is ,my age is "

.format

('shawn',22

)#從左到右括號的值:shawn,22,shawn,22

?直接傳入變數名

name =

"shawn"

age =

22print

(f"my name is ,my age is "

)

ps :速度對比: 3 > 2 > 1

python入門之使用者互動以及運算子

username input 請輸入你的使用者名稱 passwd input 請輸入你的密碼 print hello world print預設有乙個end引數,預設值是 n 換行符 print aaa end print bbb end print ccc aaabbb ccc 佔位符 s,d s...

Python入門學習 使用者互動程式

author winnie hu username input username password input password print username,password raw input 2.x input 3.x 字串拼接法 name input name age input age j...

python使用者互動

python定義字串一般用單引號或雙引號,把要表示的內容括起來,如 name linjunjie address taiwan 如果要定義的字串有多行的情況,用三個單引號 person name jj job geshou age 30 print person 列印使用者輸入的內容 name in...