In Python, assignment is a statement, and thus cannot be done with simple lambdas, which can only contain expressions (function calls, variables, attributes, ... not statements, returns1, breaks, ...). To do what you're wanting to do, you must define a normal function as so:
f = False
def onclick():
global f
f = True
This will access the global namescape's f, (use nonlocal if you're within another function) and use that variable within the function. By assigning to this you will change its value in the outer scope.
Note that you must have f defined in the outer scope before the function can reassign it.
To use it, set the command to onclick as such:
b1=Button(root,text="test", command=onclick)
A lambda isn't necessary as you're passing the function object
Note that the function definition must occur before it is passed as the command argument to the new Button
1: By this I mean returning from an outer function, not returns within the lambda, as the entire lambda expression itself is returned.