Python Repeat Question. It's a bit confusing

Asked 2 years ago, Updated 2 years ago, 18 views

Hi, everyone.

I have a question about the following Python code. What I'm going to ask is a question about code with this structure in Python repeat

a = [i for i in features if i != alphabet]

In the repetition code above, the syntax for i in features if i!= alphabet makes sense.

But what is the i at the front for?

I don't quite understand.

python

2022-09-20 19:45

1 Answers

a = [i for i in features if i != alphabet]

The above code is translated as follows:

This is what happens when you change the third step of the above translation to obtain i*2.

a = [i*2 for i in features if i != alphabet]

Finally... Why i? Since the iterator is called an iterator in English, it is i after the first letter. That's just why most repetitions in most languages typically use i.


2022-09-20 19:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.