How do I change the active object please?

For a project I’m working on it would be extremely helpful if I could make an object the active object by using its name. Or if that isn’t possible, using its index number in a collection. Anything. I don’t mind what it is, I just really want a way to do this and I can’t find any information on it.
I’d be extremely grateful for any help or suggestions. Thanks for reading.

bpy.context.view_layer.objects.active = bpy.data.objects['YourObjectName']

thank you so much, thats perfect for what im doing. id been trying to find something like this for months, i really appreciate you taking the time to tell me the solution.