Having a personal Python Teacher using ChatGPT
And how to take advantage of this amazing tool to enhance our Python skills

ChatGPT can do many cool things. One of them is writing code. You only need to give the right instruction and ChatGPT will do the job for you.
If you want to learn Python, ChatGPT is a great resource to get started. It can help you find the perfect library you need to use, solve any coding questions you might have or even code for you!
In this article, I will outline how you can use ChatGPT to learn Python and become proficient in this valuable language.
Let’s figure it out together!👇🏻
First things first, so… what’s exactly ChatGPT?
ChatGPT defines itself as a large language model trained by OpenAI. It is capable of generating human-like text based on the input it receives and can be used to answer questions and engage in conversations with people.
So basically, we can take advantage of its knowledge — and its capacity to tell us anything in a very simple and human way — to learn python and improve our current skills.
#1. Practice writing Python code
You can ask ChatGPT to give you coding challenges and then write the code to solve them. This will help you get hands-on experience with the language and improve your coding skills.
For instance, I can ask ChatGPT:
Can you give me some problems to solve in Python?
ChatGPT gives us 5 different problems to be solved, as you can observe in the following image:

You can try to solve them and check the answer using ChatGPT as well. I coded the following code to answer the first problem:
def max_num(x):
return max(x)And ChatGPT told me my answer is alright, as you can observe in the following screenshot.

Or I can rather ask for the solutions right away and try to understand them — or ask ChatGPT to further explain them to me.

#2. Understand some Python-specific concepts
If you are struggling with a particular concept or syntax in Python, you can ask ChatGPT to explain it to you in more detail. This can be a helpful way to get a better understanding of how the language works.
For instance, I can ask about the list element in Python.
What’s a list in Python?
And ChatGPT will generate a complete and easy-to-understand answer explaining the list concept and using samples to further simplify it.

You can try asking any command you are unfamiliar with! Give it a chance :)
#3. Learn about Python libraries and framework
Python has a large number of libraries and frameworks that can be used for various tasks, such as web development, data analysis, and machine learning. ChatGPT can help you learn about these tools and how to use them in your own projects.
Just imagine I want to create some good-looking interactive map in Python.
What libraries should I use to create an interactive map in Python?

As you can observe, ChatGPT recommened me four of them. But I can still ask for more detailed explanations:

I can even ask for the basic commands or some more specific actions to perform.

The craziest part? I can even ask for some code I can use right away.
Give some code I can use right now using Geopandas
ChatGPT answered me with the following code. To use it, it gave me the sample dataset as well. (contained in this link)
import geopandas as gpd
import matplotlib.pyplot as plt
# Read the shapefile into a GeoDataFrame
gdf = gpd.read_file('path/to/ne_110m_populated_places.shp')
# Select rows where the 'POP_MAX' column is greater than 10000
selected_rows = gdf[gdf['POP_MAX'] > 10000]
# Plot the selected rows on a map
selected_rows.plot(color='red')
# Show the map
plt.show()Just following it withou changing a single letter, it worked!! Crazy, huh?

#4. Ask ChatGPT to code for you
The best part of ChatGPT is that it has plenty of ideas and knowledge. This is why we can even ask it to facilitate some already working python code — just as during the previous example.
Code me how to scrape the ChatGPT website
And ChatGPT answers right away:
To scrape the ChatGPT webpage, you can use the Python library
BeautifulSoupalong with therequestslibrary to fetch the HTML content of the webpage and parse it. Here is some example code that demonstrates how you can do this:
import requests
from bs4 import BeautifulSoup
# Fetch the HTML content of the webpage
url = 'https://openai.com/blog/chatgpt/'
response = requests.get(url)
html = response.text
# Parse the HTML content
soup = BeautifulSoup(html, 'html.parser')
# Find all the paragraphs in the HTML
paragraphs = soup.find_all('p')
# Print the text of the paragraphs
for p in paragraphs:
print(p.text)Just copying once again the previous code on my jupyter notebook, it works!

I can even ask to send ChatGPT how to send an automatic email to my google account. The following code was provided by ChatGPT.
import smtplib
# Set up the SMTP server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'your-password')
# Send the email
to = '[email protected]'
subject = 'Test Email'
body = 'This is a test email sent from Python.'
msg = f'Subject: {subject}\n\n{body}'
server.sendmail('[email protected]', to, msg)
# Disconnect from the server
server.quit()Copying it and executing it in my Jupyter Notebook… voilà! I just received the corresponding email right away!

Cool!!! Isn’t it?? You can just ask whatever you want — your imagination is your only limit.
#5. Get help with your code
The last but not least thing you can do with ChatGPT is to debug your code. If you are having trouble with your Python code, you can ask ChatGPT for help with debugging. It can suggest possible solutions or strategies for troubleshooting your code.
Just imagine I want to compute the fibonacci serie. However, I defined the following function that does not work properly:
def fibonacci_of(n):
if n in {0, 1}: # Base case
return n
return fibonacci_of(n) + fibonacci_of(n) # Recursive caseI can ask ChatGPT:
Does this function computes the fibonacci serie? [Insert function here]
And ChatGPT answers me that the function is incorrect and corrects it to me:

You can even ask ChatGPT to correct your code so it follows the Pep-8 style code.
Convert the following code to Pep-8 [Insert code here]
As you can observe in the following image, ChatGPT not only corrects my code but explains step by step how to adjust it to fulfill Pep-8.

You can try to challenge ChatGPT with more complex questions!
Main Conclusions
ChatGPT is here to help you learn Python in a more interactive and personalized way. It can offer guidance, explanations, and suggestions as you work on programming exercises and projects.
This is why you can take advantage of ChatGPT knowledge — and get all its resources to help you further understand Python and its various libraries and frameworks.
Let me know if ChatGPT surprises you with some other good features. I will read you in the comments! :D
Do you want to try the new AI autonomous model — AutoGPT?
Just give a look at the following article!
Data always has a better idea — trust it.
You can suscribe to my Medium Newsletter to stay tuned and receive my content. I promise it will be unique!
If you are not a full Medium member yet, just check it out here to support me and many other writers. It really helps :D
Some other nice medium related articles you should go check out! :D
