4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-02-22

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系を使うことをおすすめします。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?