I am trying to automatize a process. I need to extract a string and previously assigned it a variable. For example:
H=8
Hello= "Hello"
Hi=(Hello[0])
print(H)
print(Hi)
Console prints:
8
H
and I need the console to print:
8
8
I am trying to automatize a process. I need to extract a string and previously assigned it a variable. For example:
H=8
Hello= "Hello"
Hi=(Hello[0])
print(H)
print(Hi)
Console prints:
8
H
and I need the console to print:
8
8
Use a dictionary instead.
Any method that solves this how you want it to be solved will be unsafe and bad practice.
data = {'H': 8, 'B': 3}
Hello = "Hello"
Hi = data[Hello[0]]
print(data['H'])
print(Hi)
Output:
8
8