filmov
tv
LEARN MOJO TUTORIAL - 14 HOW TO CREATE YOUR FIRST JUPYTER NOTEBOOK IN MOJO

Показать описание
In this video, we are going to create our first jupyter notebook for Mojo using Visual Studio code and Jupyter. So let's see how we can do that with Mojo. I'm using Visual Studio Code because it supports syntax highlighting for Mojo. And now we can say we want to create a new file. And here we have text files that we can create.
We can create Python files. And this time we are going to use this entry. It is called a Jupyter notebook. It looks like this actually. I have to admit that I hated these notebooks when I got started.
But after you have used them for a while, you get used to it and they have a few advantages. So if you don't know how these notebooks work, you can basically run a cell of code and that cell is executed when you press the little button here. Or you can also press the super key, which is the Windows key in Windows - and the Enter key. One of the advantages is that these cells are easy to edit and rerun if you make a mistake. So, as a practical example, I would like to run some Python code here.
Mojo is able to execute strict Python code when you start the cell with %%python, like I did here. So let's say my string equals this is Python code executed as Python code. And now I can run either this one cell or if I have multiple cells, I could also run all. Let's start by running this one. I have now to select a kernel here.
So I picked the one from the Mojo installation and so far nothing happened. But when I rerun it, you can see that we have a few seconds that are counted here, which means the code is actually executed. The green mark says it's a success. So let's add a print statement here and rerun the cell. And sure enough, it says this is Python code executed as Python code.
Now we are done with the first part. So let's add a new cell here. And this time we would like to use Python code in Mojo. So we can import it by creating this instance here. And it equals Python import module builtins, which stands for the functionality that is built into Python without external libraries and stuff.
Now let's create a new string. It's the same variable, but with a different value. And now I can use the print function that is included in Python to print out the string. So let's execute the second cell. And now we have seen how Python functions can be used right inside of Mojo.
All you need to do is to import it. And if I would like to use Len, I could also do that. So let's rerun the cell and we don't need to rerun the one above. That seems to work. Now let's try the Mojo print function, run it again and we get the length of the python string, and it was calculated by Python.
And in this little video, you have learned how to create your first Jupyter notebook for Mojo, how to execute raw Python code, and how to import Python functions so that you can use them in Mojo. Okay, that's it. For this video, I would like to say thank you for watching, and I will see you in the next one.
We can create Python files. And this time we are going to use this entry. It is called a Jupyter notebook. It looks like this actually. I have to admit that I hated these notebooks when I got started.
But after you have used them for a while, you get used to it and they have a few advantages. So if you don't know how these notebooks work, you can basically run a cell of code and that cell is executed when you press the little button here. Or you can also press the super key, which is the Windows key in Windows - and the Enter key. One of the advantages is that these cells are easy to edit and rerun if you make a mistake. So, as a practical example, I would like to run some Python code here.
Mojo is able to execute strict Python code when you start the cell with %%python, like I did here. So let's say my string equals this is Python code executed as Python code. And now I can run either this one cell or if I have multiple cells, I could also run all. Let's start by running this one. I have now to select a kernel here.
So I picked the one from the Mojo installation and so far nothing happened. But when I rerun it, you can see that we have a few seconds that are counted here, which means the code is actually executed. The green mark says it's a success. So let's add a print statement here and rerun the cell. And sure enough, it says this is Python code executed as Python code.
Now we are done with the first part. So let's add a new cell here. And this time we would like to use Python code in Mojo. So we can import it by creating this instance here. And it equals Python import module builtins, which stands for the functionality that is built into Python without external libraries and stuff.
Now let's create a new string. It's the same variable, but with a different value. And now I can use the print function that is included in Python to print out the string. So let's execute the second cell. And now we have seen how Python functions can be used right inside of Mojo.
All you need to do is to import it. And if I would like to use Len, I could also do that. So let's rerun the cell and we don't need to rerun the one above. That seems to work. Now let's try the Mojo print function, run it again and we get the length of the python string, and it was calculated by Python.
And in this little video, you have learned how to create your first Jupyter notebook for Mojo, how to execute raw Python code, and how to import Python functions so that you can use them in Mojo. Okay, that's it. For this video, I would like to say thank you for watching, and I will see you in the next one.