-: Welcome back.
So in this video we'll have a look
at GitHub Copilot prompting.
We'll also make sure that your installation is successful.
So what you should do is in the bottom right here,
you should have this icon.
And then if you see, here it should say,
would you like to disable Copilot?
So we know that Copilot is running.
Another way to test that would be to open up
the 0_single_line_comments.py file
and just have a look and just literally start adding a space
and watching it as Copilot pulls out
this multi-line comment inside of Python.
Cool, let's move on and step it up a notch.
We can also define complete functions
and what those functions should do
inside of Python comments.
So in this example, we've got a function called get name
and return name that takes in a single argument name
and returns, hello name, and then let's see how Copilot
starts to deal with this comment.
Great, so now we've made the function.
Let's also do this one which says,
import the datetime package
and then create a function
that returns today's date and time.
So sometimes here you've got an example
where Copilot isn't starting.
So what I'd recommend is doing something like something
like this whilst adding a def
and then that will trigger Copilot
to then know the next piece of information
that it needs is to make a function name.
As well as that, we don't also just have to use comments.
We could, for example, make a really explicit function name
and then decide to see what happens.
So in this one we've got Return State today's string
using their datetime package.
We can see that Copilot is really able to understand
when we make a very explicit function names,
it knows exactly what needs to happen inside the function.
Let's also take this if statements.
We've got a data Python list with a single key
of a dictionary, single item of a dictionary,
and inside that we've got a customer,
product, quantity and price
and we're saying if the first customer is customer one,
then print customer is the first customer.
So again, Copilot is able to handle if statements.
Let's step it up an notch and look at looping.
We can say, for example, loop over all the customers.
Notice how as well as that, Copilot has copied
some of our original code from the if_statements.py.
The reason why the Copilot is doing this
is 'cause it's scanning your entire project directory
all at the same time.
This could be quite useful because it understands
and starts to learn your individual coding patterns.
Let's have a look at a typing example in Python,
where you can also do things such as import Pandas,
get first customers age with a data frame, which is a type
of PD.dataframe is passed in.
Pandas is really clever
and what we can see here is Copilot not only generates
the documentation for the function given the types,
but it also is able to work out the return type,
knowing that it's probably likely to be an integer.
Also, notice how it's using some package functionality
from Pandas.
Without adding the type, maybe it wouldn't have been able
to reach that extra information.
So having types in your code also helps Copilots understand
what are the types going into the function
and what are the types that should go out of the function.
So far in this video, we've had a look
at all the different ways that I recommend using Copilot.
So not just using it in comments,
but using it for function names.
Also using it inside of your control flow,
such as if statements, for and while loops, et cetera.