Discuss / Python / 该函数输入字符报错,原因在哪?

该函数输入字符报错,原因在哪?

Topic source

sword_v1

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3 
# -*- coding: utf-8 -*-

def myabs(x):
    if (isinstance(x,(int,float))):    
        if (x > 0):
            return(x)
        else:
            return(-x)
    else: 
        print('%s is not numerical.' % x)

我跑了没问题

sword_v1

#3 Created at ... [Delete] [Delete and Lock User]

我去,我也不知道啥情况,后来就可以了。。。

ChuaNZzq

#4 Created at ... [Delete] [Delete and Lock User]

你的这一行代码# -- coding: utf-8 --打错了,"-"因改为"_"。所以报错


  • 1

Reply