Each function call gets its own temporary workspace. When a call starts, Python creates a fresh local scope; the parameters and every variable assigned inside the function live there. When the call returns, that workspace is thrown away. So if a function f has the body y = 5, the variable y exists only during a call to f, and reading y at the top level afterwards raises NameError: name 'y' is not defined.
Lookup runs from the inside out. When code reads a name, Python checks the local scope first, then any enclosing function, then the global scope, then the built-in names; this order is called the LEGB rule. With a global x = 10, a function that only reads x sees 10. Two functions can each have a local count without a collision, because each lives in its own workspace.
The surprise is assignment, and it is the case that looks like a lost update but is not. If a function runs x = 99, Python treats x as a new local variable for the whole function, which shadows the global: inside, x is 99, but the global x is still 10 afterwards. Nothing was lost; there are two variables sharing one name. A function that runs x = x + 1 fails with UnboundLocalError for the same reason, since that local x has no value yet. Declaring global x makes Python use the outer variable, but passing the value in and returning the result is usually the cleaner fix.
Think of it like this. Each function is a room with one-way glass. From inside, you can look out and read the notices on the hallway board, the globals; from the hallway, nobody can see into the room. Writing a name inside the room pins a new note on the room's own wall rather than changing the hallway board, unless you declare global.
Core idea. Scope prevents name collisions. Two functions can each have a variable called 'count' without interfering with each other.