str在python中用法

Python015

str在python中用法,第1张

Python中的str可以表示字符串类,也可以是将变量强制转换为字符串的函数,写作str()。str函数是Python内置函数的一种,可以直接使用,无需调用。扩展资料

python中srt的全称是SubRip Text,srt文件打开方式srt文件可以使用系统自带的.文本处理器来打开,比如notepad.exe,write.exe,word等文件处理软件。在Python中,str 表示字符串类 ,也可以是将变量强制转换为字符串的函数,写作str()。

是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思。

str():将变量转化为字符串类型

a = 1

b = [1, 2, 3]

str_a = str(a)

print(a)

print(type(a))

str_b = str(b)

print(b)

print(type(b))

The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate representations which can be read by

the interpreter (or will force a SyntaxError if there is not equivalent syntax). For objects which don't have a particular representation for human consumption, str() will

return the same value as repr(). Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings and。

是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思。

str():将变量转化为字符串类型

a = 1

b = [1, 2, 3]

str_a = str(a)

print(a)

print(type(a))

str_b = str(b)

print(b)

print(type(b))

The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate representations which can be read by

the interpreter (or will force a SyntaxError if there is not equivalent syntax). For objects which don't have a particular representation for human consumption, str() will

return the same value as repr(). Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings and。