Register Login

Python 3.6 New Features and Updates

Updated May 19, 2018

What's New in Python 3.6

New Improved Syntax for Numeric Literals

First syntactic change in the python 3.6 is the new improved syntax for the numeric literals you can see this in the ex here so what you can do now is you can add this underscore character to space your no. literals apart and this is not gonna make a symantic difference, this is just purely a way for formatting your no., and kind of how they look in your source code, but still this can be a really handy features.

If you dealing with prices or if you dealing with constants here like if you have this hexadecimal constants with a bunch of binary flag this could be really a good way to space that out and make that a lot more readable.

>>> six_figures = 100_000
>>> six_figures

>>> programmer_error = 0xbad_c0ffee
>>> flags = 0b_0111_0101_0001_0101

I think this is a really cool change its something that was available in the swift programming language as well and it's really nice to see you know some of these new features getting added to python as well. In my opinion that’s 1 of the reasons you gonna go for python 3, the language is under active development, there are new and awesome features are added with every single release.

It's really cool change, you can find more about that in PEP 515.

Improved String Interpolation

What my favourite features in this new Python release is the improved string interpolation. So, what that does is it adds yet another way to format strings in Python and its called the Formatted Strings literals, and this is a new way of formatting to use embedded Python expressions, inside your string constants.

So here’s an example for this right , so basically what do you do is find a new string and just put an ‘f’ at the beginning can like you would do with lower case ‘r’ for raw string, then you can use this new syntax using this curly braces and then put a Python expression .In this case. you are going to pull the value from the ‘name’ variable and gonna end up with this string ‘Hello Ram’ & because its just  takes an arbitrary Python expressions, you can do or you can evaluate a Python expression. You can do arithmetic or anything you want.

>>> name = 'Ram'
>>> f'Hello, {name}!'
'Hello, Ram!'

For example in this case of finding 2 variables and in the string constant and doing a bunch of maths on that resulting in ‘Eight plus six is 14 and not 28’ and recalculating like on the fly within add string syntax, & I think this is really cool. Its very similar to the way the template literals work and the new iterations of the JAVA script and this is something that I really enjoy in using JAVA script.

>>> a = 8
>>> b = 6
>>> f'Eight plus six is {a + b} and not {2 * (a + b)}.'
'Eight plus six is 14 and not 28.'

So, I think this is a great addition to Python language as well. This format strings they have some more cool features for ex you can use all of these syntax, formatting syntax that is available in the string.format call ,

Again you can learn all about the change in PEP 498.

Type Annotation Changes

Type Annotation Changes, there is new syntax to annotate the type 4 just stand alone variable and I think these type hints are really interesting. I think they are really interesting directions the language is going in and I think there gonna be a really huge impact on how you gonna use Python in the next couple of years.

You can see here is that this was possible already in Python 3.5, where you can define this Type hints.

>>> def my_add(a: int, b: int) -> int:
... return a + b

Do it for function arguments, and also for function return values and now with Python 3.6 this syntax is more flexible.

>>> python_version : float = 3.6

So you can use the same syntax for this like colon within the type 4 , you know the stand alone variables which I think is kind of cool. You have to do that with a special, specially formatted comment which I don’t think is ideal, and this makes it a lot cleaner and I think this just makes the whole like writing type Python approach a lot more valuable.

Faster Dictionaries

Another cool update is that dictionaries are a lot faster and the use, well they are faster. I don’t think they are actually lot faster but they’re faster which is good right bcz these are like free improvement that you’re getting for your Python Program. & they’re actually using quite a less memory now which is a cool change as well.

Stable API Typing Module

Another cool thing in typing area is that the typing module is now considered as the stable API which wasn’t there previously and kind of polished some of that & I think now it is quite stable foundation and people they are gonna be able to built there type programs on the top of it.

I think this gonna be huge benefit of Python for a long run, bcz it just make it so much more flexible and we’re gonna be able to apply it in so many context which did not really make sense previously to used Python. There is also a secret module to generate cryptographically secure random strings basically that is super useful if you develop or build any kind of web App and authentication app where you wanna create this authentication tokens and previously it was really easy to shoot yourself up and to accidentally create insecure tokens and with this secret modules this is all getting cleaned up and I think this is so valuable addition for web development and other kinds of programs you might write in Python as well.