If branch depending on whether there is a specific element in the list

bunki.py


#!/usr/bin/python
# -*- coding:utf-8 -*-

#Appropriate list for the time being
list = ['dog', 'cat', 'bird']

#Element to be a branch condition
a = 'dog'

"""
a in list is true(The element of a is included in the list)If it is, if is executed, if false, else is executed.
It can also be written as a not in list, and it is true if a is not included in the list.
"""
if a in list:
    print 'if_do'
else:
    print 'else_do'

Recommended Posts

If branch depending on whether there is a specific element in the list
[Golang] Check if a specific character string is included in the character string
Check if there is a specific symbol in the executable file and its dependent libraries (simplified version)
Check if the string is a number in python
How to check in Python if one of the elements of a list is in another list
Get the number of specific elements in a python list
Is there a bias in the numbers that appear in the Fibonacci numbers?
When reading an image with SimpleITK, there is a problem if there is Japanese in the path
Is there a special in scipy? ??
Python will fail if there is a space after the backslash
Delete a particular character in Python if it is the last
What to do if there is a decimal in python json .dumps
Change the list in a for statement
Is there NaN in the pandas DataFrame?
In Python, change the behavior of the method depending on how it is called
A note on customizing the dict list class
Make a copy of the list in Python
Get only the subclass elements in a list
Determining if there are birds in the image
Clone with a specific branch / tag in GitPython
Isn't there a default value in the dictionary?
Get a row containing a specific element in np.where
Get the value of a specific key in a list from the dictionary type in the list with Python
How to identify the element with the smallest number of characters in a Python list?
The Linux emulator "iSH" that runs on the iPad is a hot topic in me
How to find the first element that matches your criteria in a Python list
Checks if there is a specific character string for all files under the directory that is Python and outputs the target line
If there were no DI containers in the world.
Check if it is Unix in the scripting language
Determine if an attribute is defined in the object
Check if the LAN cable is disconnected on Linux
Difference in results depending on the argument of multiprocess.Process
Write a log-scale histogram on the x-axis in python
Check if it is Unix in the scripting language
Creating a list when the nomenclature is a fixed time
Get the value of a specific key up to the specified index in the dictionary list in Python
The return value of len or unichr may change depending on whether it is UCS-2 or UCS-4.
Recursively get the Excel list in a specific folder with python and write it to Excel.
Use Heroku in python to notify Slack when a specific word is muttered on Twitter
[Sublime Text 2] Always execute a specific file in the project
A note on the default behavior of collate_fn in PyTorch
Differences in sys.path depending on how Python is started (v3.8.2)
Test.py is not reflected on the web server in Python3.
The AWS IP range is different depending on the acquisition method.
Create a list in Python with all followers on twitter
[python] Reverse with slices! !! (There is also a commentary on slices!)
[Pandas] If the first row data is in the header in DataFrame
[Jinja2] Changes in line breaks depending on the hyphen position
How to get the last (last) value in a list in Python
Get the number of occurrences for each element in the list
Create a new list by combining duplicate elements in the list
Is there a secret to the frequency of pi numbers?
Extract the value closest to a value from a Python list element
In the python dictionary, if a non-existent key is accessed, initialize it with an arbitrary value
I made a function to check if the webhook is received in Lambda for the time being
Yield in a class that inherits unittest.TestCase didn't work with nose (depending on the version of nose?)
A comment I saw on Google+ was, "Is there an easy way to find out what number element of a list is maximum / minimum in Python?" The first line I came up with was the code on the first line, but is the second line better?