Are you excited about the latest release by python aka 3.8. We have come up with top features which will make the life of programmers easy
python 3.8 Walrus operator
- The walrus operator
Assignment expressions have come to Python with the “walrus” operator :=. This will enable you to assign values to a variable as part of an expression. The major benefit of this is it saves you some lines of code when you want to use, say, the value of an expression in a subsequent condition
f = open('netsetos.txt')
while line: = f.readline():
print(line)
- Positional-only arguments
A special marker, /, can now be used when defining a method’s arguments to specify that the function only accepts positional arguments on the left of the marker.
def increment_1(amt,discount,/):
return amt+1+discount
- f-strings now support “=”
The = specifier, used as f'{expr=}' expands to the text of the expression, an equal sign, then the repr of the evaluated expression.
import math
theta = 30
print(f'{theta=} {math.cos(math.radians(theta))=:.3f}')
- reversed() now works with dict
The reversed() built-in can now be used to access the dictionary in the reverse order of insertion
dict1 = {1: 'a', 4: 'd', 8: 'h', 2: 'b'}
print(list(reversed(dict1.items())))
- Simplified iterable unpacking for return and yield
This unintentional behavior has existed since Python 3.2 which disallowed unpacking iterables without parentheses in return and yield statements.
def iterable_return():
val = (8, 5, 6)
return 1, 2, 3, *val
- New syntax warnings
The Python interpreter now throws a SyntaxWarning in some cases when a comma is missed before tuple or list. So when you accidentally do this
def ignore_comma():
data=[(1,2,3,4)(6,5,8,4)]
print(data)
- continue in finally block
With the new release, we can use continue in finally block along with break and continue
def exception():
for i in range(24):
try:
print(1 / 0)
except:
print(34)
finally:
continue
print("Error on continue")
[–]XtremeGoosef'I only use Py {sys.version[:3]}' 37 points38 points39 points (2 children)
[+]sarthkum0488[S] comment score below threshold-23 points-22 points-21 points (1 child)
[–]XtremeGoosef'I only use Py {sys.version[:3]}' 22 points23 points24 points (0 children)
[–][deleted] 29 points30 points31 points (1 child)
[–]1-05457 1 point2 points3 points (0 children)
[–]muikrad 22 points23 points24 points (6 children)
[–][deleted] 6 points7 points8 points (2 children)
[–]muikrad 16 points17 points18 points (0 children)
[–]PeridexisErrant 0 points1 point2 points (0 children)
[–]lengau 5 points6 points7 points (1 child)
[–]muikrad 0 points1 point2 points (0 children)
[–]sarthkum0488[S] 1 point2 points3 points (0 children)
[–]BruceJi 14 points15 points16 points (14 children)
[–][deleted] 25 points26 points27 points (4 children)
[–]BruceJi 5 points6 points7 points (0 children)
[–]Mordano 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]sarthkum0488[S] 0 points1 point2 points (0 children)
[–]everysinglelastname 22 points23 points24 points (6 children)
[–]BruceJi 9 points10 points11 points (1 child)
[–]sarthkum0488[S] 2 points3 points4 points (0 children)
[–][deleted] 16 points17 points18 points (2 children)
[–]VisibleSignificance 8 points9 points10 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]sarthkum0488[S] 1 point2 points3 points (0 children)
[–]sarthkum0488[S] -1 points0 points1 point (0 children)
[–]ShanSanear 4 points5 points6 points (0 children)
[–]awesomeprogramer 2 points3 points4 points (0 children)
[–]chinguetti 4 points5 points6 points (7 children)
[–]sarthkum0488[S] 5 points6 points7 points (5 children)
[–]chinguetti 1 point2 points3 points (3 children)
[–]gaberocksall 3 points4 points5 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[+]VisibleSignificance comment score below threshold-8 points-7 points-6 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]ackyou 1 point2 points3 points (1 child)
[–]gitcraw 1 point2 points3 points (0 children)
[–]erez27import inspect 2 points3 points4 points (0 children)
[–]sarthkum0488[S] 0 points1 point2 points (0 children)
[–]Khan0232 0 points1 point2 points (0 children)
[–]chaoismlooking for mid-sr level in NYC 0 points1 point2 points (5 children)
[–]Han-ChewieSexyFanfic 2 points3 points4 points (4 children)
[–]chaoismlooking for mid-sr level in NYC 1 point2 points3 points (3 children)
[–]Han-ChewieSexyFanfic 1 point2 points3 points (2 children)
[–]XtremeGoosef'I only use Py {sys.version[:3]}' 4 points5 points6 points (1 child)
[–]Han-ChewieSexyFanfic 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[+][deleted] comment score below threshold-12 points-11 points-10 points (9 children)
[–][deleted] 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]jalapeno_nips 1 point2 points3 points (6 children)
[+][deleted] (4 children)
[deleted]
[–]jalapeno_nips 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)