There is a function eval
, which lets you evaluate a string representing a Python expression:
row1 = 'a'
eval('row1') == 'a' # True
It is, however, rarely used (Why is using 'eval' a bad practice?), and probably not what you want. You would usually store objects (like the string objects in your case) in a structure like a list or dict, and query them by index or by key:
rows = ['a','b','c']
for i in range(3):
if rows[i] == 'c':
print('pass')
The more Pythonic way is to loop over the iterable directly:
rows = ['a','b','c']
for row in rows:
if row == 'c':
print('pass')