Skip to main content
 首页 » 编程设计

python : Was expecting one of: NEWLINE>

2025年05月04日14lvdongjie

我写了

 # -*- coding: utf-8 -*-  
 
    def ANdata(key, id, format, nR, start) : 
        queryUrl = 'http://developer.website.com/api/v4/type/news?api_key=' + key + '&id=' + id + '&format=' + format + '&results=' + nR + '&start=' + start 
        print "test" 

错误是:

   Encountered "\"test\"" at line 6, column 11. Was expecting one of:     <NEWLINE> ...     "(" ...     "[" ...     ";" ...     "," ...     "." ...     "+" ...     "-" ...     "*" ...     "/" ...     "//" ...     "<<" ...      
 ">>" ...     "%" ...     "^" ...     "|" ...     "&" ...     "=" ...     ">" ...     "<" ...     "==" ...     "<=" ...     ">=" ...     "!=" ...     "+=" ...     "-=" ...     "*=" ...     "/=" ...     "//=" ...     "%=" ...     "&=" ...      
 "|=" ...     "^=" ...     "<<=" ...     ">>=" ...     "**=" ...     "or" ...     "and" ...     "not" ...     "is" ...     "in" ...     "if" ...     ";" ...     "," ... 

你看到问题了吗?

请您参考如下方法:

在 Python 3 中,print 从关键字变成了函数。所以要使用它,你必须将它的参数放在括号中:

print("test") 

在 Python 2.x 中,无论有没有括号,它都可以工作。