python常见的类型转换—list和str类型相互转化

str和repr的区别,str.join()方法的使用:

#描述:str() 函数将对象转化为适于人阅读的形式。
#返回值:返回一个对象的string格式。
str_tmp = '1234'
if str(str_tmp) == '1234':
    print('走if判断语句:'+str(str_tmp))
else:
    print('走else判断语句:'+str(str_tmp))

#描述:repr() 函数将对象转化为供解释器读取的形式。
#返回值:返回一个对象的 string 格式。
if repr(str_tmp) == '1234':
    print('走if判断语句:'+repr(str_tmp))
else:
    print('走else判断语句:'+repr(str_tmp))

猜你喜欢

转载自blog.51cto.com/7605937/2513888