亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

字符串格式化

發布時間:2020-10-15 10:36:16 來源:網絡 閱讀:98 作者:wx5c4325f004b0a 欄目:編程語言

str_1 = '字符串的格式化'
v11 = str_1.center(100,'-')
print(v11)
name = "huangyoujian"
age = 23
print("my name is %s,age is %d"%(name,age))

print("my name is %(name)s,age is %(age)d"%({'name':'haha','age':24}))

print("my name is %(name)-60s,age is %(age)d"%({'name':"laowang",'age':24}))# 左對齊
print("my name is %(name)+60s,age is %(age)d"%({'name':"laowang",'age':24}))# 右對齊

print('root','X','0','0',sep=':')
"""format字符串格式化"""
print(''50)
v = "my name is {},age is {},hobby is {}".format("huangyoujan",18,'playgame')
print(v)
print(''50)
print("可以根據索引來取值")
v1 = "my name is {2},age is {1},hobby is {0}".format("huangyoujan",18,'playgame')
print(v1)
print(''50)
print('也可以只取其中的一個值')
v2 = "my name is {1},age is {1},hobby is {1}".format("huangyoujan",18,'playgame')
print(v2)
print(''50)
print('可以傳遞一個列表')
v3 = "my name is {0},age is {1}".format(['laohuang',18])
print(v3)
print('
'50)
print('也可以傳遞一個表達式')
v4 = "my name is {name},age is {age},hobby is {name}".format(name='laowang',age=24)
print(v4)
print('
'*50)
print('還可以傳遞一個字典')
v5 = "my name is {name},age is {age},hobby is {name}".format({'name':'HYJ','age':18})
print(v5)
print(''50)
print('根據索引取傳遞列表中的值')
v6 = "my name is {0[0]},age is {0[1]},hobby is {0[2]}".format([0,1,2],[3,4])
print(v6)
print(''50)
print('按指定格式傳遞參數')
v7 = "my name is {:s},age is {:d},hobby is {:s}".format("huangyoujan",18,'playgame')
print(v7)
print(''50)
v8 = "my name is {name:s},age is {age:d},hobby is {hobby:s}".format(name="huangyoujan",age=18,hobby='playgame')
print(v8)
print(''50)
print('按指定格式傳遞一個字典')
v9 = "my name is {name:s},age is {age:d},hobby is {hobby:s}".format(
{'name':'laowang','age':18,'hobby':'playgame'})
print(v9)
print(''50)
print('進制之間的轉換')
v10 = "number:{:b},{:o},{:d},{:x},{:X},{:%}".format(15,15,15,15,15,18.54121)
print(v10)
print(''50)
v13 = "number:{0:b},{0:o},{0:d},{0:x},{0:X},{0:%}".format(15)
print(v13)

str_2 = 'END'
v12 = str_2.center(100,'-')
print(v12)

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

九江县| 东兰县| 肃宁县| 扎兰屯市| 洮南市| 宁都县| 海盐县| 民勤县| 荣成市| 赤城县| 马尔康县| 松江区| 瑞丽市| 汾阳市| 石门县| 定州市| 鄂尔多斯市| 樟树市| 元谋县| 永登县| 彩票| 宁蒗| 房产| 康乐县| 定结县| 遂溪县| 邹平县| 桐柏县| 定州市| 高要市| 怀远县| 错那县| 岱山县| 积石山| 阿克| 泽库县| 武夷山市| 汤原县| 罗田县| 米脂县| 乌拉特前旗|