In python you could specify the OP_RETURN value as follows:
from binascii import unhexlify
msg = 'your message of max 40 chars'
# convert msg to OP_RETURN script in hexadecimal
hexed = "6a%x%s" % (len(msg), msg.encode('hex'))
# convert to binary encoding
script = unhexlify(hexed)
Set the value of the output to 0.0, replace the transaction script with the binary part above.
Do not forget to add enough fee and send the remainder to your change address.