python - Why is assigning the result of print an invalid syntax? -


सरल कोड:

  & gt; & gt; & gt; A = print ('foo') फ़ाइल "& lt; stdin & gt;", पंक्ति 1 a = प्रिंट ('foo') ^ सिंटेक्स त्रुटि: अवैध वाक्यविन्यास  

क्यों? क्या प्रिंट को कोई भी वापस नहीं करना है? प्रिंट के बारे में इतना खास क्या है?

नोट: इस बात का कोई मतलब नहीं है, बस यह समझने की कोशिश कर रहा है कि यह विशिष्ट कार्य इस तरह से प्रतिक्रिया क्यों करता है।

पायथन 2 में, प्रिंट एक बयान है यह फ़ंक्शन नहीं है और इसमें "परिणाम" नहीं है हालांकि, आप इसे <__> __future__ import print_function से करके एक फ़ंक्शन बना सकते हैं, और फिर आपका उदाहरण काम करेगा। (पायथन 3 में यह हमेशा फ़ंक्शन होता है।)


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -