海詩網(wǎng) 知識百科 python(python是做什么的)

python(python是做什么的)

python, python格式函數(shù)的用法是什么?不知道小伙伴們今天來看看邊肖的分享吧!

python格式函數(shù)用法詳解:

1.位置

Print (Hello {0}, I am {1} . format (World, python)) # Fill in according to the position subscript.

Print (Hello {}, I'm {) . Format (World, python)) # Automatically fill in according to the order.

Print (Hello {0}, this is {1}. {1} is a new language . format (World, python)) # The same parameter can be filled in multiple times.

輸出:

hello world, this is python.

hello world, this is python.

hello world, this is python. python is a new language.

2. Keys

obj=world

name=python

print(hello {obj}, this is {name}.format(obj=obj, name=name))

輸出:

hello world, this is python.

python是做什么的

3.目錄

list=[world, python]

print(hello {names[0]}, this is {names[1]}.format(names=list))

輸出:

hello world, this is python.

4.詞典

dict={obj:world, name:python}

print(hello {names[obj]}, this is {names[name]}.format(names=dict))

輸出:

hello world, this is python.

注意:

訪問不帶引號的字典鍵。

5.類別屬性

class Names():

obj=world

name=python

print(hello {names.obj}, this is {names.name}.format(names=Names))

輸出:

hello world, this is python.

6.神奇參數(shù)

args=[, inx]

kwargs={obj: world, name: python}

print(hello {obj}{} this is {name}.format(*args, **kwargs))

輸出:

hello world, this is python.

注意:

這里的格式(*args,**kwargs)等價于格式(,inx,obj=world,name=python)。

第二,數(shù)字格式化

python是做什么的

第三,其他用法

1.逃跑

print({{hello}} {{{0}}}.format(world))

輸出:

{hello} {world}

2.格式化為函數(shù)變量。

name=python

hello=hello, welcome to {} world!format

print(hello(name))

輸出:

hello, welcome to python world!

3.格式化數(shù)據(jù)時間

from datetime import datetime

now=datetime.now()

print({:%Y-%m-%d %X}.format(now))

輸出:

2020-12-15 19:46:24

4.{}嵌入{}

print(hello {0:{1}} .format(world, 10))

輸出:

hello world

python是做什么的

python,以上就是本文為您收集整理的python最新內(nèi)容,希望能幫到您!更多相關(guān)內(nèi)容歡迎關(guān)注。

本文來自網(wǎng)絡(luò),不代表海詩網(wǎng)立場,轉(zhuǎn)載請注明出處:http://x91880.com/n/168031.html
      

pandas(pandas讀取excel文件)

發(fā)表回復(fù)
聯(lián)系我們
聯(lián)系我們

在線咨詢: QQ交談

郵箱: 3587015498@qq.com

工作時間:周一至周五,9:00-17:30,節(jié)假日休息

關(guān)注微信
微信掃一掃關(guān)注我們
微信掃一掃關(guān)注我們
關(guān)注微博
返回頂部