S
S
Soul12020-09-17 16:01:46
Python
Soul1, 2020-09-17 16:01:46

How to change the data type in a list?

Initially, the task was to automatically generate a list of variables from b1 to bn (in the example up to b3), I came up with only this implementation:

b1 = 12
b2 = 23
b3 = 5
v = []
name = "b"
for n in range(1, 3):
    x = str(name) + str(n)
    v.append(x)

I got the coveted list, only now I'm racking my brains on how to change the type of the object so that these objects begin to refer to the numeric values ​​​​assigned to them. Found this formula: But it doesn't work. Tell the teapot what's the catch. Maybe I don't need int at all? Or how to get around this problem and create a list of sequential variables in a simpler way (in the sense of b1, b2, b3 ... b100, provided that these variables have already been created and assigned numeric values) ?
v1 = [int(x) for x in v]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2020-09-17
@res2001

Assign values ​​directly to the list.

M
milssky, 2020-09-17
@milssky

Or just use a dictionary name:value

S
StarCatSTT, 2020-09-17
@StarCatSTT

You can't make pointers in python.
You can read: ARTICLE ON HABR

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question