+ -
当前位置:首页 → 问答吧 → python里的单个下划线 “_” 有何用处

python里的单个下划线 “_” 有何用处

时间:2011-06-29

来源:互联网

  1. import random


  2. articles = ["the", "a", "another", "her", "his"]
  3. subjects = ["cat", "dog", "horse", "man", "woman", "boy", "girl"]
  4. verbs = ["sang", "ran", "jumped", "said", "fought", "swam", "saw",
  5.          "heard", "felt", "slept", "hopped", "hoped", "cried",
  6.          "laughed", "walked"]
  7. adverbs = ["loudly", "quietly", "quickly", "slowly", "well", "badly",
  8.            "rudely", "politely"]

  9. for _ in [1, 2, 3, 4, 5]:
  10.     article = random.choice(articles)
  11.     subject = random.choice(subjects)
  12.     verb = random.choice(verbs)
  13.     if random.randint(0, 1) == 0:
  14.         print(article, subject, verb)
  15.     else:
  16.         adverb = random.choice(adverbs)
  17.         print(article, subject, verb, adverb)
  18. ~                                                                  
复制代码
请教,这个for语句里的下划线的作用

作者: leooys   发布时间: 2011-06-29

热门下载

更多