Python筆記(一)——列印輸出

來源:互聯網
上載者:User

標籤:sof   圖片   inpu   --   size   簡介   soft   輸入   pytho   

一、輸出語句input    輸出語句print

  例:使用者輸入

1 username = input("username:")2 #變數名                   顯示的字元3 password = input("password:)4 print(username,password)

二、格式化輸出

  例:簡介

1 name = input("name:")         #字元型2 age = input("age:")      3 print(type(age))               #查看age的類型  typ()輸出類型4 jop = input("jop:")5 salary = input("salary:")

   注釋:輸入得到的類型是字元型,所以age得到的是字元不是數值;若使age得到的是數值應轉換類型。

1 age = int(input("age:"))   #age是整數型

  格式化輸出四種方式

  1. 字串的拼接

 

1 info1 = """         2 ------------info1 of """ +name+ ‘‘‘------3 Name:‘‘‘ +name+ """4 Age:""" +age+ ‘‘‘5 Jop:‘‘‘ +jop+ """6 Salary:""" +salary7 print(info1)

  #字串的拼接只能用於字元
  #可使用‘‘‘ ‘‘‘或""" """ 用於多行輸出,info1已經共兩種方式寫出

  2. #預留位置 %s 字元型,%d 十進位整數型,%f 浮點型

1 info2=‘‘‘2 ---------info2 of %s------3 Name:%s4 Age:%s5 Jop:%s6 Salary:%s7 ‘‘‘%(name,name,age,jop,salary)   #按輸出順序寫8 print(info2)

  3.用.format()

1 info3 = """2 -----------info3 of {name2}-------3 Name:{name2}4 Age:{age2}5 Jop:{jop2}6 Salary:{salary2}7 """.format(name2=name,age2=age,jop2=jop,salary2=salary)  #可理解為一個數組8 print(info3)

  4.

1 info4 = """2 -----------info4 of {0}-------3 Name:{0}4 Age:{1}5 Jop:{2}6 Salary:{3}7 """.format(name,age,jop,salary)8 print(info4)

三、運行結果

 

Python筆記(一)——列印輸出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.