def
is a key word of language construction, it is not a function, it serves precisely to declare and define a function.
Your code, by posting indentation, does not do what you want, Python is indentation sensitive. So
def se():
sex = input('Digite seu sexo:')
is the function and
while sex != 'M' and sex != 'F':
is a loose code.
What you probably want is this:
def getSex():
while True:
sex = input('Digite seu sexo:')
if sex == 'M' or sex == 'F':
return sex
print(getSex())
See working on ideone. And in the repl it.. Also put on the Github for future reference.
The return
closes a function and it can optionally deliver a result to the called, as every mathematical function does (programming does not invent anything, it is all math, almost everything that is taught in school).
Of course there is much to improve on this, but the focus of the question is this.