Advertisement

Python错误:无法将字符串与整数进行除法运算

阅读量:

文章结构概览

  • 错误重现
    • 异常提示
    • 应对策略

错误复现

复制代码
    # python代码
    print('1除以2等于%f' %1/2)
    
    
      
      
    

报错

复制代码
    TypeError: unsupported operand type(s) for /: 'str' and 'int'
    
    
      
    

解决办法

在相关研究中,通过引入括号这一方式,能够有效提升文本的清晰度与表达的准确性。

复制代码
    >>> print('1除以2等于%f' %(1/2))
    1除以2等于0.500000
    
    
      
      
    

全部评论 (0)

还没有任何评论哟~