开发者

Why doesn't just a variable name display the variable in a script, like in the interpreter? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

开发者_StackOverflow社区 Improve this question

I want to display a string which is returned by a function in a Python script, without using print:

def myfunc(mystring):
    return "Converting to lowercase :{0}".format(mystring.lower())

result=myfunc("LOWER")
result

But it doesn't give an output. How can I get result to display without print?


Your code does print 'Converting to lowercase :lower' when run in an interactive session (using python or ipython).

It does not, however, print anything if run as part of a script, since there is no implicit printing of expression results.

This is how it's meant to be.

If you want to print something from a script, use print or sys.stdout.write().


An alternative to print:

sys.stdout.write()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜