20
17

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.

リスト内に特定の要素があるかでif分岐

Last updated at Posted at 2013-02-26
bunki.py
#!/usr/bin/python
# -*- coding:utf-8 -*-

#とりあえずの適当なリスト
list = ['dog', 'cat', 'bird']

#分岐条件にしたい要素
a = 'dog'

"""
a in listが真(listの中にaの要素が含まれている)ならifが実行されて、偽ならelseが実行される。
a not in listとも書けてlistの中にaが含まれていない場合が真になる。
"""
if a in list:
    print 'if_do'
else:
    print 'else_do'
20
17
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
20
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?