Jak w tytule
[ on-line ]
ficzer = 'PyTHoN'
print(f'{ficzer:*<40}')
print(f'{ficzer:*>40}')
print(f'{ficzer:*^40}')
for i in range(len(ficzer)+1, 41):
print(f'{ficzer:*>{i}}')
from datetime import datetime
print(f'Dzisiaj: {datetime.now():%d-%m-%Y %H:%M:%S}')
a = { 'lorem1': 1, 'impsum1': 2, 'dolor1': 3, 'amet1': 4 }
b = { 'lorem2': 1, 'impsum2': 2 }
c = { **a, **b }
print(c)
a, *b = [ 1,2,3,4 ]
# a b
print(a, b, sep=', ') # 1, [2, 3, 4]
a, *b, c = [ 1,2,3,4 ]
# a b c
print(a, b, c, sep=', ') # 1, [2, 3], 4
a, *b, c, d = [ 1,2,3,4 ]
# a b c d
print(a, b, c, d, sep=', ') # 1, [2], 3, 4
a, *b, c, d = [ 1,2,3 ]
# a b c d
print(a, b, c, d, sep=', ') # 1, [], 3, 4
fruit = 'BANANA'
print(*fruit) # B A N A N A
print(*fruit, sep='.') # B.A.N.A.N.A
print([*fruit]) # ['B', 'A', 'N', 'A', 'N', 'A']
tzw. "operator warunkowy"
test = [ 1, 2, 3, 4, 8, 13, 14 ]
for age in test:
status = 'infant' if age < 2 else 'toddler' if age < 4 else 'child' if age < 13 else 'teenager'
print(f'{age:2} {status}')
import time
# dynamic storage
s = time.time()
list_1 = []
for n in range(10_000_000):
list_1.append(n)
e = time.time()
print(f"{e - s}s")
# pre-allocation
s = time.time()
list_2 = [0] * 10_000_000
for n in range(10_000_000):
list_2[n] = n
e = time.time()
print(f"{e - s}s")
# cAPSLOCk ErrOR
name = "VBSerVICE"
print(name.title())
Operator trójskładnikowy wykorzystujący krotki
(test false, test true)[test]
isCool = (False, True)[feature == 'Cool']