格式化輸出py

來源:互聯網
上載者:User

標籤:%s   學習   表示   print   資料   input   字串拼接   16px   span   

# 格式化輸出
# % 預留位置 資料類型: s 字串 d:整數 f:浮點型 r:內建函數會講到 i ......
# 第一種方式
# name = input(‘請輸入姓名:‘)
# age = input(‘請輸入年齡:‘)
# job = input(‘請輸入工作:‘)
# hobby = input(‘請輸入愛好:‘)
#
# msg = """
# ------------ info of %s -----------
# Name : %s
# Age : %d
# job : %s
# Hobby: %s
# ------------- end -----------------
# """ % (name, name, int(age), job, hobby)
# print(msg)

# 第二種方式

# dic = {"name": ‘jinyuan‘, ‘age‘: 18, ‘job‘: ‘IT‘, ‘hobby‘: ‘男‘}
#
# msg = """
# ------------ info of %(name)s -----------
# Name : %(name)s
# Age : %(age)d
# job : %(job)s
# Hobby: %(hobby)s
# ------------- end -----------------
# """ % dic
# print(msg)

# 在格式化輸出中只想單純的表示% 寫%%
msg = ‘我叫%s,今年%d,學習進度5%%‘ % (‘金元‘, 18)
print(msg)

# 總結:如果你想製作一個字串類的模板,或者是想讓字串某些位置變成動態輸入,此時你想到用字串拼接,格式化輸出。

格式化輸出py

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.