matplotlib plt.sapect
plt.figure(figsize=(10,3)) plt.plot(x,y) plt.show()
Here is what the above code is Doing:
1. We’re creating a figure object with a size of 10×3.
2. We’re plotting the x and y values.
3. We’re showing the plot.
plt.figure(figsize=(10,3)) plt.plot(x,y) plt.show()
Here is what the above code is Doing:
1. We’re creating a figure object with a size of 10×3.
2. We’re plotting the x and y values.
3. We’re showing the plot.
arr = np.array([‘aasdfads’, ‘asfdads’, ‘fdfsdfaf’]) >>> [len(i) for i in arr] [8, 7, 8] Here is what the above code is Doing: 1. Create a list of strings 2. Create a new list by applying the len() function to each element of the list
def get_AJAX(request, id): data = serializers.serialize(“json”, [Template.objects.get(pk=id)]) return HttpResponse(data) Here is what the above code is Doing: 1. The get_AJAX function is called when the user clicks on the “Get Template” button. 2. The function takes the id of the template that the user wants to get. 3. The function then uses Django’s serializers to…
text_file = open(“sample.txt”, “w”) n = text_file.write(‘Welcome to pythonexamples.org’) text_file.close() Here is what the above code is Doing: 1. The open() function opens the sample.txt file in write mode. 2. The write() function writes the string ‘Welcome to pythonexamples.org’ to the file. 3. The close() function closes the file.
import os os.chdir(“**Put here the directory where you have the file with your function**”) from file import function os.chdir(“**Put here the directory where you were working**”) Here is what the above code is Doing: 1. It changes the current working directory to the directory where you have the file with your function. 2. It imports…
print(“Hewwo wowwd”) Here is what the above code is Doing: 1. We’re importing the random module. 2. We’re creating a list of possible responses. 3. We’re creating a function called “respond” that takes in a string as an argument. 4. We’re creating a variable called “response” that chooses a random response from the list of…
import math 8 * 8 # 64 8 ** 2. # 64 math.pow(8, 2) # 64.0 Here is what the above code is Doing: 1. 8 * 8 is an integer multiplication, so it returns an integer. 2. 8 ** 2. is a floating point exponentiation, so it returns a float. 3. math.pow(8, 2) is…