4.1-4.3_使用者輸入輸出與字串物件操作


> 目前你可以先想成 function 是一個販賣機,投入錢幣(輸入 input),掉出商品(輸出 output)。而 input() 的輸入則是使用者提示字元,輸出則是使用者的輸入內容(型別為字串 str)。而 print() 輸出函式則是我們一直在使用的 Python 內建函式,它會印出所傳入的參數內容到指令碼終端機畫面上。

使用者輸入

將變數指到使用者輸入的內容字串物件
user_name = input('請輸入使用者名稱')

使用者輸出

print() 輸入參數為希望印出的訊息。

補充:有回傳值可以給定給變數

int(input(請輸入一個數字:)) 因為有回傳值可以拆解等同於:

# 回傳值就可以給定給變數方便接下來程式使用
user_input = input(請輸入一個數字:)
# 使用者輸入原本是 string 字串型別,將 user_input 變數轉成 integer 整數
int(user_input)
#Python






你可能感興趣的文章

[Swift 學習筆記] Closure : Inline function process

[Swift 學習筆記] Closure : Inline function process

DAY28:Sum of the first nth term of Series

DAY28:Sum of the first nth term of Series

loading 百分比

loading 百分比






留言討論