Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add 3.8 files
  • Loading branch information
qqlexa
qqlexa committed Jun 23, 2022
commit 397921105a6bc01d096fd4ce22b9cf113395935c
15 changes: 15 additions & 0 deletions 3.8/companies_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
companies = []
if (n := len(companies)) == 1 and (first_company := companies[0]):
print(f'We have only one company: {first_company}')
elif (n := len(companies)) > 1 and (first_company := companies[0]):
print(f'We have such companies as: {", ".join(companies)}')
else:
print(f'We have no companies')

print(n)
# 1
print(first_company)
# Traceback (most recent call last):
# File "/home/user/main.py", line 12, in <module>
# print(first_company)
# NameError: name 'first_company' is not defined
12 changes: 12 additions & 0 deletions 3.8/companies_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
companies = ['Flyaps']
if (n := len(companies)) == 1 and (first_company := companies[0]):
print(f'We have only one company: {first_company}')
elif (n := len(companies)) > 1 and (first_company := companies[0]):
print(f'We have such companies as: {", ".join(companies)}')
else:
print(f'We have no companies')

print(n)
# 1
print(first_company)
# Flyaps
7 changes: 7 additions & 0 deletions 3.8/companies_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
companies = ['Flyaps', 'Google', 'Apple']
if (n := len(companies)) == 1 and (first_company := companies[0]):
print(f'We have only one company: {first_company}')
elif (n := len(companies)) > 1 and (first_company := companies[0]):
print(f'We have such companies as: {", ".join(companies)}')
else:
print(f'We have no companies')
7 changes: 7 additions & 0 deletions 3.8/csv37.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import csv

with open('file.csv', 'rt') as f:
reader = csv.DictReader(f)
for i in reader:
print(type(i)) # OrderedDict
print(type(i) == dict) # False
7 changes: 7 additions & 0 deletions 3.8/csv38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import csv

with open('file.csv', 'rt') as f:
reader = csv.DictReader(f)
for i in reader:
print(type(i))
print(type(i) == dict)
9 changes: 9 additions & 0 deletions 3.8/format_string1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from math import pi

class Employee:
name = 'Oleksii'
company = 'Flyaps'

print(f'Employee.name={Employee.name}, Employee.company={Employee.company}')
print(f'round(pi, 2) = {round(pi, 2)}')
print(f'pi = {pi:.5f}')
9 changes: 9 additions & 0 deletions 3.8/format_string2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from math import pi

class Employee:
name = 'Oleksii'
company = 'Flyaps'

print(f'{Employee.name=}, {Employee.company=}')
print(f'{round(pi, 2) = }')
print(f'{pi = :.5f}')
11 changes: 11 additions & 0 deletions 3.8/positional_parameters1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def f(a, b, /, c, d, *, e, g):
print(a, b, c, d, e, g)


# The following is a valid call:
f(10, 20, 30, d=40, e=50, g=60)


# However, these are invalid calls:
f(10, b=20, c=30, d=40, e=50, g=60) # b cannot be a keyword argument
f(10, 20, 30, 40, 50, g=60) # e must be a keyword argument
8 changes: 8 additions & 0 deletions 3.8/positional_parameters2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def divmod(a, b, /):
"""Emulate the built in divmod() function"""
return a // b, a % b


divmod(a=1, b=2)

len(obj='hello') # The "obj" keyword argument impairs readability
1 change: 1 addition & 0 deletions 3.8/positional_parameters3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
len(obj='hello') # The "obj" keyword argument impairs readability
6 changes: 6 additions & 0 deletions 3.8/positional_parameters4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def f(a, b, /, *args, **kwargs):
print(a, b, args, kwargs)


f(10, 20, 1, 2, 3, a=1, b=2, c=3) # a and b are used in two ways
# 10 20 (1, 2, 3) {'a': 1, 'b': 2, 'c': 3}
5 changes: 5 additions & 0 deletions 3.8/user_input37.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
user_input = input()
print(user_input)
while user_input:
user_input = input()
print(user_input)
2 changes: 2 additions & 0 deletions 3.8/user_input38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
while user_input := input():
print(user_input)