SyntaxError:以' \ xad'

时间:2015-11-09 17:32:12

标签: python-3.x utf-8

def pair(n, num_list):
    """function receives a list of numbers and a number(n) and returns a list of numbers which are the sum of n"""
    sum_list=[]
    num_list = [int(i) for i in num_list]
    for i in num_list:
        for j in num_list:
            if (i+j) == n:
                sum_list.append ([i,j])
    if range(len(sum_list)) == 0:
        return None
    return sum_list

num_list=["­2","3","7","11","2","6"]
num_list = [int(i) for i in num_list]
print(pair(5,num_list))

我收到了下一条消息:

  

SyntaxError:以' \ xad'开头的非UTF-8代码在文件中   第14行的C:/ex3/dsfdsf.py,但没有声明编码

我想得到:[2,3],[7,-2]

1 个答案:

答案 0 :(得分:1)

该错误来自于具有非ASCII的源文件,该文件未以UTF-8编码保存,并且在文件顶部没有#coding:语句来声明编码。由于我在第14行或任何地方的源代码中都没有看到非ASCII,因此这不一定是造成问题的确切来源。