码迷,mamicode.com
首页 > 其他好文 > 详细

str() 函数避免类型错误

时间:2018-02-08 11:06:38      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:pytho   编写   sam   python程序   报错   系统   ==   避免   引号   

在编写python程序时,需要注意字符和数字的区别。使用数字是不能加引号,而编写print语句是,则需要str()函数来避免系统混淆。否则python程序会进行报错

sample:

numbers = list(range(1,10))
if number == 1
print(str(number) + "st")

这样运行则会顺利显示:1st

str() 函数避免类型错误

标签:pytho   编写   sam   python程序   报错   系统   ==   避免   引号   

原文地址:http://blog.51cto.com/13595859/2070027

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!