You're mixing very different things in your question, so I'll just answer a different question
You are now asking about one of the most important interface in Python: iterable - it's basically anything you can use like for elem in iterable.
iterable has three descendants: sequence, generator and mapping.
A sequence is a iterable with random access. You can ask for any item of the sequence without having to consume the items before it. With this property you can build
slices, which give you more than one element at once. A slice can give you a subsequence:seq[from:until]and every nth item:seq[from:until:nth].list,tupleandstrall are sequences.If the access is done via keys instead of integer positions, you have a mapping.
dictis the basic mapping.The most basic iterable is a generator. It supports no random access and therefore no slicing. You have to consume all items in the order they are given. Generator typically only create their items when you iterate over them. The common way to create
generatorsare generator expressions. They look exactly like list comprehension, except with round brackets, for example(f(x) for x in y). Calling a function that uses theyieldkeyword returns a generator too.
The common adapter to all iterables is the iterator. iterators have the same interface as the most basic type they support, a generator. They are created explicitly by calling iter on a iterable and are used implicitly in all kinds of looping constructs.
You're mixing very different things in your question, so I'll just answer a different question
You are now asking about one of the most important interface in Python: iterable - it's basically anything you can use like for elem in iterable.
iterable has three descendants: sequence, generator and mapping.
A sequence is a iterable with random access. You can ask for any item of the sequence without having to consume the items before it. With this property you can build
slices, which give you more than one element at once. A slice can give you a subsequence:seq[from:until]and every nth item:seq[from:until:nth].list,tupleandstrall are sequences.If the access is done via keys instead of integer positions, you have a mapping.
dictis the basic mapping.The most basic iterable is a generator. It supports no random access and therefore no slicing. You have to consume all items in the order they are given. Generator typically only create their items when you iterate over them. The common way to create
generatorsare generator expressions. They look exactly like list comprehension, except with round brackets, for example(f(x) for x in y). Calling a function that uses theyieldkeyword returns a generator too.
The common adapter to all iterables is the iterator. iterators have the same interface as the most basic type they support, a generator. They are created explicitly by calling iter on a iterable and are used implicitly in all kinds of looping constructs.
listare more than plain arrays. You can initialize them without giving the number of items. You canappend/pushto them, you canremove/pop/delitems from them, you can have lists of different types of objects (e.g.,[1,'e', [3]]), you can have recursive lists... and you can slice lists, which means getting a new list with only a few of the items.sliceare an object type used "behind the scenes" to handle extended slicing in thea[start:stop:step]form, ashelp(slice)reveals.
"Sequence" is not an object, more like an informal interface some objects like list implement.
In mathematics, we define the notion of a sequence to basically be list (or tuple, or whatever) of elements. Sequences can also be infinite. And they are sometimes understood to actually be equivalent to functions with domain equal to the natural numbers, or something like that.
In computer science we talk about lists instead of sequences, usually. Lists are almost always finite, although with lazy function evaluation, you can make an infinite list data structure in OCaml. I'm not exactly sure how you would "formally" define lists, in a way that is analogous to what they do in mathematics.
But at a high level, they seem like exactly the same thing. Just one is thought of from a mathematics perspective and the other from computer science.
Is there a difference?
Question about python types: What's the difference between a types.Sequence and types.Iterable?
Is there an important difference between a sequence and a list?
Is there any difference between tuples, ordered lists and sequences?
[Python Question] Are all sequences iterable/all iterables sequences?
Can't really find info looking online. The python docs doesn't describe any difference between them, semantically they sound identical but I'm not sure I'm missing something here.