Thanks, but I would like to know how to do it myself
About 10 seconds with the Google search engine turned up the following:
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.
If you can't figure out how to use an internet search engine, it is very unlikely that you'll be able to figure out how to write a program that will allow you to build raw bitcoin transactions.