>>str(1/7)0.1428571428571428" /> >>str(1/7)0.1428571428571428" /> >>str(1/7)0.1428571428571428" />

首页 / 知识

pythonstr()函数转换字符串

2023-11-12 12:55:00

python中str()函数转换字符串

1、方法说明

如果只是想把Python的对象转换成文字串的话,str()函数是回到人类可读值的表示。

2、语法

classstr(object='')

3、实例

>>>s='Hello,world.'

>>>str(s)

'Hello,world.'

>>>repr(s)

"'Hello,world.'"

>>>str(1/7)

'0.14285714285714285'

>>>x=10*3.25

>>>y=200*200

>>>s='Thevalueofxis'+repr(x)+',andyis'+repr(y)+'...'

>>>print(s)

Thevalueofxis32.5,andyis40000...

>>>#Therepr()ofastringaddsstringquotesandbackslashes:

...hello='hello,world\n'

>>>hellos=repr(hello)

>>>print(hellos)

'hello,world\n'

>>>#Theargumenttorepr()maybeanyPythonobject:

...repr((x,y,('spam','eggs')))

"(32.5,40000,('spam','eggs'))"

以上就是python中str()函数转换字符串的方法,希望对大家有所帮助。更多Python学习教程请关注我们

培训字符串函数成文语法

最新内容

相关内容

热门文章

推荐文章

标签云

猜你喜欢