How python is special in Today's world
Python supports Artificial Intelligence, Machine Learning, Data Science, Web Development, Scientific computing, GUI, etc.
Python is a general-purpose language, object-oriented programming language, Scripting language, high-level programming language, dynamic typing language, Interpreted language.
Every revision of Python enjoys performance improvements over the previous version. python recently python 3.9 released with new features. In Python 3.9, several Python built-in functions like range, tuple, set, frozenset, list, dictionary use the vector call to speed up execution. The next big performance enhancer is the more efficient parsing of Python source code. The new parser for the CPython runtime wasn’t designed to address performance issues, but rather to deal with internal inconsistencies in the original parser. However, an important fringe benefit is faster parsing, especially for large volumes of code.
New features in 3.9
Dictionary Merge & Update Operators
Merge (
|
) and update (|=
) operators have been added to the built-in dict class. Those complement the existingdict.update
and{**d1, **d2}
methods of merging dictionaries.Example a={1:’a’ ,2:’b’,3:’c’} b={3:’c’,4:’d’} a|b
Output:
{1:’a’,2:’b’,3:’c’,4:’d’}
Type Hinting Generics in Standard Collections
Example
def greet_all(names: list[str]) -> None:
for name in names:
print(“Hello”, name)
NEW MODULES
Python supports multiple programming paradigms
Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented, and functional programming. Python is often described as a “batteries included” language due to its comprehensive standard library. Python also joins with other languages like C, Java also adds some features. Examples JPython, CPython.
Python object inferring
It gives better memory management in python. If two variables assigned to the same value then in the same memory location both will point not in different memory locations. This is called as an object inferring. Example.
DECORATOR
Decorators
Without changing the function definition we can change the functionality using decorators.
Example
import functools
def swap(func):
def inner(a,b):
if(a<b):
a,b=b,a
return func(a,b)
return inner
@swap
def sub(a,b):
return(a-b)
print(sub(2,5))
Output:
3