-3

これを試してみて、Pythonに非常に慣れていない -

def newlines():
    print()
    print()
    print()    
question = "Which online Course you have signed up, dude?"
response = "Good Luck to you, dude!"
print(question), newlines(), input(), newlines(), print(response)

Python 3.2.* では、出力は次のとおりです。

Which online Course you have signed up, dude?



Nothing



Good Luck to you, dude!

(None, None, "Nothing", None) # Where this output is coming from ?

また、これはpython 3.3ベータ版では発生していません

4

2 に答える 2

5

インタラクティブ シェルにいる必要があります。コードをファイルとして実行すると、次の出力が得られます。

$ python3.2 test.py
Which online Course you have signed up, dude?



dlkjdf



Good Luck to you, dude!
$

コンソールでのみ出力を取得します。

>>> def newlines():
...     print()
...     print()
...     print()    
... 
>>> question = "Which online Course you have signed up, dude?"
>>> response = "Good Luck to you, dude!"
>>> 
>>> print(question), newlines(), input(), newlines(), print(response)
Which online Course you have signed up, dude?



dljdldk



Good Luck to you, dude!
(None, None, 'dljdldk', None, None)
>>> 

これは、コンソールが最後に入力した内容の表現を出力するためです。最後のステートメントは実際にはタプルなので、最後に出力されます。以下にいくつかの例を示します。

>>> 3
3
>>> 4
4
>>> 3, 4, None, "hey"
(3, 4, None, 'hey')
于 2012-08-04T19:56:49.193 に答える
2

これを書くとき:

print(question), newlines(), input(), newlines(), print(response)

実際には、各関数の結果を保持するタプルです。

個々の回線で通話を分割するだけで、問題は解決します。

print(question)
newlines()
input()
newlines()
print(response)
于 2012-08-04T19:54:15.943 に答える