Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@Hawk84

Python2.6で制御構造を扱う際の注意

Python 2.6を使っている人へ。
2.6だと以下のコードはエラーになる。

for i in range(10):
  if(i%2 == 0):
      print("{} is even".format(i))
  else:
      print("{} is odd".format(i))
print("done")

2.6は上記の書き方ではだめみたい。
http://stackoverflow.com/questions/10054122/valueerror-zero-length-field-name-in-format-python

for i in range(10):
  if(i%2 == 0):
      print("{0} is even\n".format(i))
  else:
      print("{0} is odd\n".format(i))
print("done")

とすれば動く。

2.7か3系を使うことをおすすめします。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What are the problem?