Watch a lot of comedy and think about why it's funny. To be a comedy writer you need to have a large knowledge of comedians, jokes, comedy techniques, stories and more. Watch your favorite movies or sitcoms, and try to think about just why it is so funny. Take notes if that helps.
Study scriptwriting formats. There are many books and websites that can teach you the basic script format. You need to learn this if you want to write for TV or movies.
Write a "spec script." A spec script is a script you wrote on speculation, meaning that you don't know for sure if it'll be made or not. If you're writing a movie, write a full-length screenplay. If you're writing for a TV show, write a script for an existing TV show, preferably one that's only been on TV for a season or so. Also, become well informed of the show's style, and decide what would make sense for an episode. For aspiring TV comedy writers, it's generally a good idea to write two spec scripts.
Submit your scripts to an agent. You'll need an agent before a television producer will read your script. The same can be true for aspiring movie writers. For a list of agents associated with the Writers Guild of America, see the link in the "Resources" section. If they are interested in working with you, they will then submit your scripts to producers and other people that can help bring your script to life on TV or in the movies.