Python 3.8 - New useful features

Python has been a language for everyone, it covers almost every integrity of computer science. With Python 3.7 its evolved with more technical features of it.

Now, 3.8 shows some interesting updates with respect to operators, debugging and also arguments.



  • First one is Positional feature '/' 
Using '/' inside the functional Arguments which can be used to change the variable names and values with respect to it.

In general, this can be a bit unusual to use it as this can be complex.


def calc(x, y, z, /, smile="smile",a):  #please note the "/" in this argument list
    print(smile)
    a=750
    return x+y+z+a

print(calc(5, 10, 20, smile="have a smile",a))

You can make the position of x,y,z to be stable and also it can be made variable with the letters assignment.

  • The second one is Walrus ':-"
This is not a new one obviously for R-language users. Walrus is an operator which combines assignment operation with respect to expression.

Mostly useful in while loop and do while loop cases and also switch case.

if len(name :=(a+b ) > 5: #let a and b be string variables.

  • The Third one is f string
This one sounds great with respect to debug cases.

name = 'techie'

print(f'Name: { name }')
print(f'{name=}')

f string directly prints out variable value irrespective of a data type.

For, me personally Python with huge covering over the years, it is still updaitng the basic is some what to cheer about.

Interestingly, f string and Walrus will be my favourite ones out here to opt for.

Comment your opionions.

Post a Comment

0 Comments