How to create collections?

I am still quite new to Python scripting in Blender. Right now, I am reading through the Quickstart in the API documentation.

In an example, where a custom property is added to a collection, a new collection is created with the following line of code

collection ="MyTestCollection")

I read in the documentation for collection operators that you can also create a collection with bpy.ops.collection.create.

collection =["MyTestCollection"]

However, in both cases, the result is not visible in the outliner. (Is that bad?)

Could anybody please explain whether both ways of creating a collection are equivalent?
If not, in what cases should we use one or another ?

When using api you need to link it to parent collection, via

When using operator, most likely it adds it to active collection defined by context.

Thanks for the linking to parent explanation!

After running

collection ="MyTestCollection")


bpy.ops.collection.create(name  = "MyTestCollection")["MyTestCollection"])

the collection is created and shown in the outliner.

I still wonder whether these two ways of creating a collection are equivalent ?
If they are not equivalent, which is preferred in what situation ?

In general, operators are UI-oriented. They rely on context and use selected/active stuff and so on.

Oh, I see the difference now.
On a new file (with Blender defaults)"MyTestCollection") creates an empty collection whereas bpy.ops.collection.create("MyTestCollection") creates a collection that contains the default cube. This is in line with your explanation because when opening a new file, the cube is active/selected.