Python print "hello world" SyntaxError: invalid syntax
2013-07-26 15:14
369 查看
刚安装Python,在IDLE中输入print “Hello World”,谁知却发生错误:
>>> print "Hello World"
SyntaxError: invalid syntax
而在朋友的机子上测试却运行无误,经查得知这是Python 版本不同所致。朋友用的是2.x版本,而我用的是3.x版本
正确命令:print("Hello World")
问题是通过用help命令解决的。输入help(print)就知道print的正确用法了。
>>> help(print)Help on built-in function print in module builtins:
print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
2013-07-26 15:13:28
>>> print "Hello World"
SyntaxError: invalid syntax
而在朋友的机子上测试却运行无误,经查得知这是Python 版本不同所致。朋友用的是2.x版本,而我用的是3.x版本
正确命令:print("Hello World")
问题是通过用help命令解决的。输入help(print)就知道print的正确用法了。
>>> help(print)Help on built-in function print in module builtins:
print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
2013-07-26 15:13:28
相关文章推荐
- python print'hello' File "<stdin>",line 1 print 'hello' SyntaxError:invalid syntax
- python print'hello' File "<stdin>",line 1 print 'hello' SyntaxError:invalid syntax
- python 3.4.0 简单的print 'hello world',出错--SyntaxError: invalid syntax
- Python 入门 hello,world SyntaxError: invalid syntax
- 【python3.3.2】 首次接触python print 出现SyntaxError: invalid syntax
- Python 3.2.3 print 出现SyntaxError: invalid syntax
- 【python】print "hello" SyntaxError: Missing parentheses in call to 'print'
- Python 3.2.3 print 出现SyntaxError: invalid syntax
- python print SyntaxError: invalid syntax
- Ubuntu:python helloworld.py SyntaxError: invalid syntax
- python-gtk-3-tutorial(2)--"Print hello world"
- python报错 print "hello" SyntaxError: Missing parentheses in call to 'print'
- python :print SyntaxError: invalid syntax错误的问题
- python d:\test.py File "<stdin>", line 1 python d:\test.py ^ SyntaxError: invalid syntax
- Python 3.x中使用print函数出现语法错误(SyntaxError: invalid syntax)的原因
- python 3.4.0 简单的print 'hello world',出错--SyntaxError: invalid syntax
- Python 3.2.3 print 出现SyntaxError: invalid syntax
- Python 3.* print 出现SyntaxError: invalid syntax
- Python 3.4.1 print 出现SyntaxError: invalid syntax
- Python之print "hello" SyntaxError: Missing parentheses in call to