1 name = input("請輸入暱稱:")
2 age = input("
請輸入年齡:")
3 money = input("
請輸入年薪:")
4 hobby = input("
請輸入興趣:")
56#變數賦值
7print("""
****************
8姓名:
9年齡:歲
10年薪:萬
11興趣:
12****************
13""".format(ag=age, mon=money, hob=hobby, nickname=name))
1415
#順序賦值
16print("
我的暱稱是:{},我的年齡是:{}歲,我的愛好是:{}
".format(name, age, hobby))17#
佔位符中加索引
18print("
我的暱稱是:,我的年齡是:歲,我的愛好是:,我的年薪是:萬
".format(hobby, age, money, name))
執行結果:
請輸入暱稱:奔奔請輸入年齡:20請輸入年薪:100請輸入興趣:python
****************姓名:奔奔
年齡:20歲
年薪:100萬
興趣:python
****************我的暱稱是:奔奔,我的年齡是:20歲,我的愛好是:python,我的年薪是:100萬
我的暱稱是:奔奔,我的年齡是:20歲,我的愛好是:python,我的年薪是:100萬
python 格式輸出( 用法和format)
今天修改程式,比較糾結用哪個,搜資料整理一下。format 用法相對於基本格式 的用法,功能要強大很多。將字串當成模板,通過傳入的引數進行格式化,並且使用大括號 作為特殊字元代替 correct print the number is d 20 輸出 the number is 20 error p...
python格式化輸出 format
對於很多時候,題目要求你要去保留小數點後幾位小數,或者是整數按位輸出,不足補0,python中提供的format函式能夠讓你輕鬆地實現。format函式有兩個引數,含義如下 1.第乙個引數為要格式化的數字 2.第二個引數為格式化字串。format的返回值就是數字格式化後的字串。num 1234.56...
python 格式化輸出format
1.1 format與基本格式化輸出的區別 1 基本格式化輸出採用 的方法 2 format 通過傳入的引數進行格式化,使用大括號 作為特殊字元代替 使用方法有兩種 b.format a 和format a,b 1.2 基本用法 1.2.1 簡單輸出 用法 結果說明 不帶編號 format hell...