Title: random.choice input 3 args but error msg say 4 args given · Issue #3 · softnshare/python · GitHub
Open Graph Title: random.choice input 3 args but error msg say 4 args given · Issue #3 · softnshare/python
X Title: random.choice input 3 args but error msg say 4 args given · Issue #3 · softnshare/python
Description: Question 我在工作上是用 ruby,這幾天開始學python,有個狀況不太懂,想跟大家請教一下 想請問為什麼它說我給了4個 arguments?? 我看起來只給了3個args 事情是這樣的,我的 random.choice 寫錯了 但 error msg 的內容讓我很好奇,如下: # 錯誤寫法 >>> random.choice(1,2,3) Traceback (most recent call last): File "
Open Graph Description: Question 我在工作上是用 ruby,這幾天開始學python,有個狀況不太懂,想跟大家請教一下 想請問為什麼它說我給了4個 arguments?? 我看起來只給了3個args 事情是這樣的,我的 random.choice 寫錯了 但 error msg 的內容讓我很好奇,如下: # 錯誤寫法 >>> random.choice(1,2,3) Traceback (most rece...
X Description: Question 我在工作上是用 ruby,這幾天開始學python,有個狀況不太懂,想跟大家請教一下 想請問為什麼它說我給了4個 arguments?? 我看起來只給了3個args 事情是這樣的,我的 random.choice 寫錯了 但 error msg 的內容讓我很好奇,如下: # 錯誤寫法 >>> random.choice(1,2,3) Traceback (...
Opengraph URL: https://github.com/softnshare/python/issues/3
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"random.choice input 3 args but error msg say 4 args given","articleBody":"## Question\n\n我在工作上是用 ruby,這幾天開始學python,有個狀況不太懂,想跟大家請教一下\n想請問為什麼它說我給了4個 arguments?? 我看起來只給了3個args\n\n事情是這樣的,我的 random.choice 寫錯了\n但 error msg 的內容讓我很好奇,如下: \n\n```\n# 錯誤寫法\n\u003e\u003e\u003e random.choice(1,2,3)\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nTypeError: choice() takes exactly 2 arguments (4 given)\n```\n\n我給了3個 arguments,error msg 卻說 4 given,why~?!!!\n## Answers\n\n@raytong \nrandom.choice 應該是 def choice(self, array), 所以比你原來的多了一個 argument\nhttp://openhome.cc/Gossip/Python/Class.html\n\n@d2207197 \nrandom 是 Random class 的 instance。所有 instance method 第一個參數是 self,會自動給。\n建議用 ipython 來當 REPL 不要用 python,會好用很多。\n在 ipython 上可用 `?` 與 `??` 來查文件。以你的例子就是\n`import random\nradom.choice??`\n另外有 browser 的話可以用 jupyter notebook ,開發和測試。自己電腦懶得裝可以先到 https://tmpnb.org 玩\n## 結論\n\n原因在於 choice 的定義大概是像這樣\ndef deposit(self, array):\n也是為什麼它只接受一個array,卻表示 choice() takes exactly 2 arguments\n因為第一個 arg 是 self,會自動賦予\n\n正確寫法\n\n``` python\n*正確寫法*\n\n random.choice([1,2,3])\n2\n```\n\n要加入Slack Python討論channe請參考[入口網頁](https://softnshare.wordpress.com/slack/python/)\n","author":{"url":"https://github.com/jcsky","@type":"Person","name":"jcsky"},"datePublished":"2016-06-16T03:23:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/3/python/issues/3"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:46471407-7a67-2320-156a-1752ffd63f91 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B67E:D45B7:2A596F:3990BE:698F254F |
| html-safe-nonce | bea6ad5cc0f5be4dcd7c7590e62c2aae37484c9836dfb6fb34ddc2f41cd015a3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjdFOkQ0NUI3OjJBNTk2RjozOTkwQkU6Njk4RjI1NEYiLCJ2aXNpdG9yX2lkIjoiNTE4NzE0OTU5NzA1OTc4NjA2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 47339094b14f15334827de78a1da00d5f2a4e180e3c20f7cf015d2bdf4acc0db |
| hovercard-subject-tag | issue:160569667 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/softnshare/python/3/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a85f3e0d212e48ffe4aaa25900543b41684a5f9de13262826c897e172b92b267/softnshare/python/issues/3 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a85f3e0d212e48ffe4aaa25900543b41684a5f9de13262826c897e172b92b267/softnshare/python/issues/3 |
| og:image:alt | Question 我在工作上是用 ruby,這幾天開始學python,有個狀況不太懂,想跟大家請教一下 想請問為什麼它說我給了4個 arguments?? 我看起來只給了3個args 事情是這樣的,我的 random.choice 寫錯了 但 error msg 的內容讓我很好奇,如下: # 錯誤寫法 >>> random.choice(1,2,3) Traceback (most rece... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jcsky |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6102991c714c1a6a27d05fb4f96ea6ca87a6750b4f093b95cc57ed1b84b145a1 |
| turbo-cache-control | no-preview |
| go-import | github.com/softnshare/python git https://github.com/softnshare/python.git |
| octolytics-dimension-user_id | 18457860 |
| octolytics-dimension-user_login | softnshare |
| octolytics-dimension-repository_id | 59437234 |
| octolytics-dimension-repository_nwo | softnshare/python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 59437234 |
| octolytics-dimension-repository_network_root_nwo | softnshare/python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d52a41ad9b9ffb9b63a1b4a600a6054be8b70b36 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width