You can use a list with the for statement, to process each element of the list in turn:
segmentlist = ["MSH", "EVN", "PID", "NK1", "PV1"]
for segment in segmentlist:
print segment
# prints each segment name on its own line
You can also use a list with an if statement:
segmentlist = ["MSH", "EVN", "PID", "NK1", "PV1"]
segment = "PID"if segment in segmentlist:
print segment, "is a segment in the list"if segment notin segmentlist:
print segment, "is not a segment in the list"
This is a convenient way to determine whether a value matches, or does not match, one of a number of acceptable alternatives.