Today I learned - 052019 - What is 'from __future__ import print_function' in Python? | from __future__ import print_function 的用法

in #ilovecoding7 years ago

python_bgd

相信許多剛學 python / ML 的朋友會在網上閱讀代碼的時候會看到下面語句:

from __future__ import print_function

那麼這行代碼有什麼意思呢?

有許多人的 python environment 還是 python 2。若是想使用 python 3 語法的話,便需要這行代碼了。因為那 python 3 對於 python 2 就是future,也就是說,在python 2 的環境下,超前使用python 3 的打印函數。

from __future__ import print_function
print('Hello Steem') # output: Hello Steem
print 'Hello Steem' # Error
Sort:  

感谢代理20.04SP 给team-cn! 由于你使用CN作为你的标签,额外获得1%点赞! 你的帖子获得team-cn 7% 点赞!(如果不想看到这个回复,请回复“取消”)

Thank you for your continued support towards JJM. For each 1000 JJM you are holding, you can get an additional 1% of upvote. 10,000JJM would give you a 11% daily voting from the 600K SP virus707 account.

Hi @nuagnorab!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 2.993 which ranks you at #10320 across all Steem accounts.
Your rank has dropped 7 places in the last three days (old rank 10313).

In our last Algorithmic Curation Round, consisting of 151 contributions, your post is ranked at #62.

Evaluation of your UA score:
  • Only a few people are following you, try to convince more people with good work.
  • The readers like your work!
  • Good user engagement!

Feel free to join our @steem-ua Discord server

!magicdice

Posted using Partiko iOS

Hello @nuagnorab

You requested your Magic Dice details.

You were referred to Magic Dice by jaydih and have 1 referrals.
You are currently delegating 99.99999960287239 Steem Power.

You have placed 877 bets with a 76.51% win rate.

You have wagered 1,219.489000 STEEM and 892.836000 SBD.
You have won 1,135.003000 STEEM and 875.876000 SBD.
Your profit is -84.486000 STEEM and -16.960000 SBD.

You received 0.021752 STEEM and 0.077602 SBD in referral bonuses.
You received 6.563142 STEEM and 0.033788 SBD in dividends.

Your absolute profit/loss is: -77.923000 STEEM and -16.927000 SBD

You have acquired 87,862.297600 Magic Tokens.
Your spent per 1M Magic Tokens: 961.572000 STEEM and 193.033000 SBD.