天天看點

Python 報錯問題:Encountered "counter" at line 8, column 7. Was expecting one of:

源碼:

#!/usr/bin/python

# -*- coding: UTF-8 -*-

counter = 100 # 指派整型變量

miles = 1000.0 # 浮點型

name = "John" # 字元串

print counter

print miles

print name

eclipse報錯如下:

Encountered "counter" at line 8, column 7. Was expecting one of:     

 <NEWLINE> ...     "(" ...     "[" ...     ";" ...     "," ...     "." ...     "+" ...     "-" 

 ...     "*" ...     "/" ...     "//" ...     "<<" ...     ">>" ...     "%" ...     "^" ...     "|" 

 ...     "&" ...     "=" ...     ">" ...     "<" ...     "==" ...     "<=" ...     ">=" ...     

 "!=" ...     "+=" ...     "-=" ...     "*=" ...     "@=" ...     "/=" ...     "//=" ...     

 "%=" ...     "&=" ...     "|=" ...     "^=" ...     "<<=" ...     ">>=" ...     "**=" 

 ...     "or" ...     "and" ...     "not" ...     "is" ...     "in" ...     "if" ...     "@" ...     

 ";" ...     "," ...     

Encountered "counter" at line 8, column 7. Was expecting one of:     

 <NEWLINE> ...     "(" ...     "[" ...     ";" ...     "," ...     "." ...     "+" ...     "-" 

 ...     "*" ...     "/" ...     "//" ...     "<<" ...     ">>" ...     "%" ...     "^" ...     "|" 

 ...     "&" ...     "=" ...     ">" ...     "<" ...     "==" ...     "<=" ...     ">=" ...     

 "!=" ...     "+=" ...     "-=" ...     "*=" ...     "@=" ...     "/=" ...     "//=" ...     

 "%=" ...     "&=" ...     "|=" ...     "^=" ...     "<<=" ...     ">>=" ...     "**=" 

 ...     "or" ...     "and" ...     "not" ...     "is" ...     "in" ...     "if" ...     "@" ...     

 ";" ...     "," ...

原因:

python3.0版本後print需要用()

詳細參考https://stackoverflow.com/questions/19878100/python-was-expecting-one-of-newline

修改如下:

#!/usr/bin/python

# -*- coding: UTF-8 -*-

counter = 100 # 指派整型變量

miles = 1000.0 # 浮點型

name = "John" # 字元串

print (counter)

print (miles)

print (name)