python_objects.html
001| """Python Objects. Everything is an object!"""
002| print('='*80)
003| print()
004|
005|
006| hi = "Hello, World!"[0:5]
007| uc = "hello, world!".upper()
008| rv = "Hello, World!"[::-1]
009| print(f'{hi=}, {uc=!s}, rev={rv}')
010| print()
011|
012| hello = "Hello, World!"
013| hi = hello[0:5]
014| uc = hello.upper()
015| rv = hello[::-1]
016|
017| nbits = (42).bit_length()
018| n1bits = (42).bit_count()
019| print(f'42: bits={nbits}, bytes={(nbits//8)+1}, ones={n1bits}')
020| the_bytes = (42).to_bytes(1, 'little')
021| print(f'42 is {the_bytes[0]:X} in hex')
022| print()
023| print('='*80)
024| print()
025|
026| func = lambda x: pow(x,2.718281828)
027| print(f'f(0)={func(0)}')
028| print(f'f(1)={func(1)}')
029| print(f'f(2)={func(2)}')
030| print(f'f(2.5)={func(2.5)}')
031| print()
032| print('-'*80)
033| print()
034|
035| numlst = lambda n: list(range(1,n+1))
036| nums = numlst(10)
037| print(f'{nums = }')
038| print()
039|
040| vals = [func(num) for num in nums]
041| print(f'nums^e = {vals}')
042| print()
043|
044|
045|
046| def numlst2 (n:int) -> list:
047| """Return list [0,1,...n]."""
048| nums = []
049| for n in range(n):
050| nums.append(n+1)
051| return nums
052| print(f'{nums = }')
053| print()
054|
055| nums = numlst2(10)
056| vals = []
057| for num in nums:
058| val = func(num)
059| vals.append(val)
060| print(f'nums^e = {vals}')
061| print()
062|
063|
064| print('='*80)
065| print()
066| """eof"""
067|