2020
09-25
09-25
Python %r和%s区别代码实例解析
%r用rper()方法处理对象%s用str()方法处理对象相同结果有些情况下,两者处理的结果是一样的,比如说处理int型对象。例:print('Iam%syearsold.'%22)print('Iam%ryearsold.'%22)返回结果:Iam22yearsold.Iam22yearsold.不同结果例:x="Thereare%dtypesofpeople."%10print('Isaid:%r'%x)print('Isaid:%s'%x)返回结果Isaid:'Thereare10typesofpeople.'#通过%r保留了原有所有属性Isaid:...
继续阅读 >