How does storage work with programs run in containers?

Suppose I make a Python or C program and it calls a file system function, what happens? Where is the data written? And does it last beyond the duration of the container?

In general how do system calls work which result in persistent system changes? (File creation, etc)?)

With a plain container, data is written within container. When you update the container, data is lost.

To persist data, usually bind mounts (doc) are used to map a host folder into the container or Docker volumes (doc), which have a separate lifecycle than containers.