Create Jokes Using Python

Hello Techies,

Now-a-days most of us love to read jokes for programmers. In this tutorial I will explain you how one can create a joke for a programmer using python.

Video Tutorial is available on my YouTube Channel Tech Blooded Tutorial

Python supports creation of random jokes using one of its libraries. That library is pyjokes.

Pyjokes is a python library that is used to create one-line jokes for programmers. Informally, it can also be referred to as a fun python library which is pretty simple to use. Let us see how we can actually use it to perform the required task. And the task is to create jokes.

We can simply install it using the following command

Use following code to import it in your python script .

And by importing that library to our python script we can use it in our code. So to create a joke we can use get_joke() function , this function has 2 parameters :

  • language of joke
  • category of joke

Possible values for language parameters are English , German , Spanish , Italian , Galician and Basque. And the default value is English.

Possible values for the joke category are Neutral , Tongue Twister and All. And the default value is Neutral.

#create a single joke #language is english and from neutral category joke = pyjokes.get_joke(language='en',category='neutral')

2 . To generate the list of jokes we can use the get_jokes() function. In this function the parameters are the same as the previous function.

#create list of jokesjoke = pyjokes.get_jokes(language='en',category='all')
for i in range(5):

So now you can generate a joke anytime you want with your python skills.

So Techies, I hope you all understood the tutorial to generate a joke and list of jokes using pyjokes.

If you loved this article , please show some love by subscribing My page and YouTube channel .

For more articles visit my page Amol Ambkar

Originally published at

Computer Enginnering Student