How to overwrite file in python

I want to overwrite a file using python code. Can you tell me how to do it ? and how many ways we have in python to overwrite a file in python?