相关疑难解决方法(0)

为什么在Python 2.7中自动打印括号?

在Python 2.7中,以下两者都是相同的

print("Hello, World!") # Prints "Hello, World!"

print "Hello, World!" # Prints "Hello, World!"
Run Code Online (Sandbox Code Playgroud)

但是以下不会

print("Hello,", "World!") # Prints the tuple: ("Hello,", "World!")

print "Hello,", "World!" # Prints the words "Hello, World!"
Run Code Online (Sandbox Code Playgroud)

在Python 3.x括号中print是必需的,基本上使它成为一个函数,但在2.7中,两者都将使用不同的结果.我还应该print在Python 2.7中了解什么?

python printing python-2.7 python-3.x

97
推荐指数
3
解决办法
8万
查看次数

SyntaxError:print'string1中的语法无效:',string1

可能重复:
"print"附近的SyntaxError?

我是python的第一次用户.我刚刚在我的计算机上安装了Python 3.3,更新了PATH并尝试运行我刚刚复制的第一个python程序并将其从教程粘贴到新文件中.我收到的错误是:

File "C:\Users\bmahnke\Desktop\python.py", line 23
      print 'string1 is: ', string1

SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我不确定问题是什么,因为我是从教程网站得到的,我不确定,但差不多,他们不会在那里放一个不能编译的文件.所以我想知道我做错了什么

这是我正在使用的python代码:

#! C:\Python33\python.exe

string1 = 'In this class,'
string2 = 'I am learning to program in'
string3 = 'PYTHON.'

print 'string1 is: ', string1
print 'string2 is: ', string2
print 'string3 is: ', string3
print 'Put them altogether and you get:'
print string1, string2, string3
print string1 + string2 + string3
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏,谢谢.

python compiler-errors

0
推荐指数
1
解决办法
830
查看次数