Why do we use 'with' statement for tf.GradientTape?

I have a very basic question about tf.GradientTape.
When we use it in the Lab2, we use ‘with’ statement.
Lab 2: Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera

What is the reason for that?
What does ‘with’ statement do in this specific context?
I am not accustomed with ‘with’ statement and I need some advice on this particular use case.
I would appreciate it if anyone can guide me understanding it.
Thanks in advance
Best Regards

Here are some readings about ‘with’ statement in Python in general:

Here is one explanation specifically about how GradientTape uses ‘with’ statement: python - How to reuse the inner gradient in nested gradient tapes? - Stack Overflow.

1 Like

Hi @Heryandi
Thanks for your followup.
Sorry for my belated feedback.
I will check those resources that you provided me with.
Thanks again
Kind regards.