I made a variable.
body_weight_1 = [34, 45, 45, 65, 56]
body_weight_2 = [33, 30, 40, 50, 90]
And, I expected to print 'body'.
str(body_weight_1)[:4]
But, the result is
[34
how to get word 'body' from 'body_weight_1' in this situation?
I made a variable.
body_weight_1 = [34, 45, 45, 65, 56]
body_weight_2 = [33, 30, 40, 50, 90]
And, I expected to print 'body'.
str(body_weight_1)[:4]
But, the result is
[34
how to get word 'body' from 'body_weight_1' in this situation?
How I already commented here is that its not that easy to get the string of a virable name. Instead you can create a dictionary:
data = {
'body_weight_1': [34, 45, 45, 65, 56],
'body_weight_2': [33, 30, 40, 50, 90]
}
for key in data :
# prints the first 4 chars of all keys
print(key[:4])
Output:
>> body
>> body