As you know by now, Michael Python and see, Python had two different programming languages Micro Python
has copied, Python is faithfully as possible to create a high level language programming experience
for microcontrollers.
There are differences between the two languages, which I would like to summarize in the next few minutes.
Now, the differences between micro python and Python are documented in detail in the Python website.
There you can find a full list of those differences, as well as code examples that demonstrate them.
In this lecture, I will mention only some of those differences that I believe are more relevant for
the purposes of this course.
So let's begin with syntax in Python.
You can do things like forget to put a space between a literal number and a keyword to form an expression,
and they will be OK.
Python has enough flexibility to forgive mistakes like this.
The same mistake in my code.
Python, however, will generate a syntax error.
Mokra Python developers had to throw away the logic needed to deal with tab was like that in order to
make it fit in the limited storage of the target devices.
Another example of the differences between the two languages is how the self Keywood is handled when
self is used in a function in Python.
It does not count it as an additional argument, but Michael Python does.
As a result, if you provide an incorrect number of arguments to a function that contains self Keywood,
then the error message it will get in Python will be different to what you get in micro python.
I've got an example here.
You can see this example.
I'm calling the same function calculator both in Python and Python, and I'm putting a single argument.
I should have passed two arguments, but I made a mistake.
It just a single argument here you can see them and coding the exact same function with this same parameter.
But the messages that are coming back to indicate the error are different.
So, see, Python is telling me that I've got one required argument missing where your python is telling
me that in total that are supposed to be three arguments I've only given to in fact, I've given one.
So you can see that the message that is coming through here in Python is or can be a bit confusing,
which can throw you off and cause you to delay you debarking.
As long as you are aware of the situation with the self key word, I think you'll be able to get past
issues like this.
Here's another subtle difference that has to do with formatting in this particular example of a floating
point number.
When you print out formatted floating point numbers, the result may differ between Python and C Python
here, printing out this floating number and using the same exact commands between you, Python and
C Python, you python being Mokra, Python.
And you can see that what comes out is different in each occasion.
In this case, the G operator, when used with C Python, applies the exponential format to a number
in the output.
The chief operator differs between the two implementations.
OK, next example of differences is the string C.
Python, as you may know, contains powerful string manipulation functions and not all of them are available
on micro python.
Two examples are start with and end with these allow you to check if a string starts or ends with a
specific character or string of characters in Micro Python.
These functions only work in their basic format without the start and end indexed parameters.
In the example here in this slide, you can see that the call to the end with function fails when we
use it with the three parameters, but work with a single parameter in Python.
No problem.
Either one will just work properly and as expected.
All right, next up.
We've got Jason, and this course will use the micropayment Jason module to work with Internet of Things
services, unlike, say, Python and the Python version of the Jason module, you, Jason, does not
throw an exception if an object is not serializable.
And this means that if your program receives a JSON document from a Web service that is not valid,
you will not be able to deal with it gracefully.
Using an exception handler, you will have to deal with this manually or your program will just crash.
All right, so these were just some of this subtle differences between see Python and the micro python
implementation and of course, there are many more.
The best place again, to learn about them and about the changes is the python documentation in the
next lecture.
I'll show you some of the best online resources for Macur Python.
And these are the resources that you'll want to watch so that we can access them anytime that you with
Michael.