python - Pythonic way to iterate through a range starting at 1 -


currently if want iterate 1 through n use following method:

for _ in range(1, n+1):     print(_) 

is there cleaner way accomplish without having reference n + 1 ?

it seems odd if want iterate range ordinally starting @ 1, not uncommon, have specify increase 1 twice:

  1. with 1 @ start of range.
  2. with + 1 @ end of range.

range(1, n+1) not considered duplication, can see might become hassle if going change 1 number.

this removes duplication using generator:

for _ in (number+1 number in range(5)):     print(_) 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -