Skip to content

Latest commit

 

History

History
97 lines (82 loc) · 1.6 KB

025.What_is_python3.8.md

File metadata and controls

97 lines (82 loc) · 1.6 KB

What Is Python 3.8

Base

Whatsnew 3.8

https://docs.python.org/3.8/whatsnew/3.8.html#porting-to-python-3-8

https://www.python.org/downloads/release/python-380/

:=

# A
>>> val = False
>>> print(val)
False

# B
>>> print(val := False)
False
# A
inputs = list()
while True:
    current = input("Write something: ")
    if current == "quit":
        break
    inputs.append(current)

# B
inputs = list()
while (current := input("Write something: ")) != "quit":
    inputs.append(current)

/

# A
>>> def incr(x):
...     return x + 1
...
>>> incr(3.8)
4.8
>>> incr(x=3.8)
4.8

# B
>>> def incr(x, /):
...     return x + 1
...
>>> incr(3.8)
4.8
>>> incr(x=3.8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: incr() got some positional-only arguments passed as keyword arguments: 'x'

>>> def incr(x, /, a="Hello"):
...     return f"{greeting}, {name}"
...
>>> incr("Łukasz")
'Hello, Łukasz'
>>> incr("Łukasz", a="Awesome job")
'Awesome job, Łukasz'
>>> incr("Łukasz", "Awesome job")
'Awesome job, Łukasz'
>>> incr(x="Łukasz", a="Awesome job")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: incr() got some positional-only arguments passed as keyword arguments: 'x'

type

# A
def incr(number):
    return 2 * number

# B
def incr(number: float) -> float:
    return 2 * number

f""

>>> style = "formatted"
>>> f"This is a {style} string"
'This is a formatted string'

More TODO