Tue May 20 22:25:36 2025 python_intrinsics_test(): python version: 3.10.12 numpy version: 1.26.4 Test python_intrinsics(). abs_test(): abs() returns the absolute value of a number. x abs(x) 155.241294 155.241294 -102.555298 102.555298 -143.287609 143.287609 116.586020 116.586020 -250.967742 250.967742 89.302793 89.302793 -33.228136 33.228136 42.634967 42.634967 -40.167222 40.167222 -67.192316 67.192316 -3507275 3507275 -86715644 86715644 86048557 86048557 -36778424 36778424 19870530 19870530 -91510854 91510854 -4409486 4409486 -27381289 27381289 -20507774 20507774 46948610 46948610 all_test(): all() returns True if all elements are True. a = [ -2 , 4 , 12 ] all(a<10) False all(a!=0) True (all(-5? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~X dir_test(): dir() lists objects. dir(x) lists methods and properties of object x The dir() command actually only prints information during interactive use, so the following dir() commands will not print out anything, since we are running noninteractively. After defining a, b, c, and d, issue "dir()" ['a', 'b', 'c', 'd', 'pprint', 'string'] Issue "dir(b)" ['__abs__', '__add__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getformat__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__int__', '__le__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__pos__', '__pow__', '__radd__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmod__', '__rmul__', '__round__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__setformat__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', 'as_integer_ratio', 'conjugate', 'fromhex', 'hex', 'imag', 'is_integer', 'real'] divmod_test(): divmod(a,b) returns the rounded quotient and remainder of a/b. a b q r 152 -90 -2 -28 -230 71 -4 54 -658 60 -11 2 194 10 19 4 798 -70 -12 -42 -463 19 -25 12 954 -91 -11 -47 499 8 62 3 578 -90 -7 -52 538 -64 -9 -38 53.327769 -0.005994 -8897.000000 -0.001093 -175.588139 4.837336 -37.000000 3.393303 88.187018 7.952320 11.000000 0.711494 -17.514858 23.421606 -1.000000 5.906748 23.282866 5.094893 4.000000 2.903293 -32.681748 -1.317740 24.000000 -1.055995 14.186754 -9.619996 -2.000000 -5.053237 -14.571556 -7.283515 2.000000 -0.004526 64.810967 14.335927 4.000000 7.467258 154.438430 0.146302 1055.000000 0.089523 eval_test(): eval() takes a string, which might represent a formula, and evaluates it. x = 1 s = ' x + 9 ', eval(s) = 10 x = 101 s = ' x + 9 ', eval(s) = 110 a = 1.2 b = 8.0 s = ' a * b + 1 ', eval(s) = 10.6 float_test(): float() returns the float version of a value. a = 123456 , float(a)= 123456.0 a = 3.141592653589793 , float(a)= 3.141592653589793 a = ' 123.456 ', float(a)= 123.456 globals_test(): globals() lists the global variables. {'__annotations__': {}, '__builtins__': , '__cached__': None, '__doc__': None, '__file__': '/home/john/public_html/py_src/python_intrinsics_test/python_intrinsics_test.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x70e6df821150>, '__name__': '__main__', '__package__': None, '__spec__': None, 'abs_test': , 'all_test': , 'any_test': , 'bin_test': , 'bool_test': , 'bytearray_test': , 'chr_test': , 'dir_test': , 'divmod_test': , 'eval_test': , 'float_test': , 'globals_test': , 'hash_test': , 'hex_test': , 'id_test': , 'int_test': , 'len_test': , 'locals_test': , 'max_test': , 'min_test': , 'oct_test': , 'ord_test': , 'pow_test': , 'python_intrinsics_test': , 'range_test': , 'reversed_test': , 'round_test': , 'slice_test': , 'sorted_test': , 'sum_test': , 'timestamp': } hash_test(): hash() returns a hash value. x hash(x) -1 -2 -2 -2 -3 -3 0 0 1 1 2 2 12345 12345 2019 2019 -11 -11 691752902764109836 691752902764109836 0 0 1 1 3.14159265359 326490430436040707 12345.6789 1565436818957021241 ' a' 523442476209347660 ' abcde' -5514684261454886885 ' 12345' -2803428057152189749 hex_test(): hex() returns a string that is the hexadecimal representation of an integer. i hex(i) 0 0x0 1 0x1 2 0x2 3 0x3 4 0x4 5 0x5 10 0xa 20 0x14 30 0x1e 2019 0x7e3 -11 -0xb id_test(): id() returns the unique identifing number of an object. a = 3.141592653589793 id(a)= 124136896592208 b = 3 id(b)= 124136895545648 c = Hallelujah! id(c)= 124136893697200 d = [1 2 3] id(d)= 124136607824944 e = id_test, id(e) = 124136893519840 int_test(): int() returns the integer version of a value. You cannot convert a complex value. You cannot convert a string which includes a decimal point. a = 3.141592653589793 , int(a)= 3 a = 4.5 , int(a)= 4 a = 5.5 , int(a)= 5 a = ' 904 ', int(a)= 904 a = ' 101 ', int(a,2)= 5 a = ' 101 ', int(a,5)= 26 a = ' 101 ', int(a,10)= 101 a = ' 101 ', int(a,16)= 257 len_test(): len() returns the length of a string, tuple, or list. x=range(5,10) len(x) = 5 x='Matlab' len(x) = 6 x = [ 10, 11, 12 ] len(x) = 3 x = ( 10, 11, 12 ) len(x) = 3 locals_test(): locals() lists the local variables. {'a': 1, 'b': 2.3, 'c': 'Who is that?', 'data': array([-1, -2, -3]), 'e': (4, 5, 6), 'np': , 'pprint': } max_test(): max() returns the maximum of a pair of arguments, or an array. max(a,b) returns the maximum of a and b. a b max(a,b) -817 -389 -389 -208 -383 -208 319 50 319 637 -29 637 -81 900 900 -442 934 934 -76 547 547 -504 482 482 145 -303 145 318 -722 318 max(a) returns the maximum element of a. a1 a2 a3 max(a) -787 -389 770 770 138 -571 -691 138 -492 403 -741 403 901 967 883 967 372 -466 68 372 439 159 -189 439 -758 -997 -783 -758 -300 88 -678 88 -666 -939 -83 -83 -454 -522 283 283 min_test(): min() returns the minimum of a pair of arguments, or an array. min(a,b) returns the minimum of a and b. a b min(a,b) 30.89 -88.75 -88.75 -3.84 -109.94 -109.94 55.48 -42.42 -42.42 72.16 -14.76 -14.76 63.87 45.68 45.68 129.99 75.46 75.46 -234.11 30.01 -234.11 -4.06 -148.93 -148.93 -64.63 61.04 -64.63 111.62 51.41 51.41 min(a) returns the minimum element of a. a1 a2 a3 min(a) -41.89 117.29 53.81 -41.89 52.37 -32.91 -72.29 -72.29 190.57 -19.63 18.24 -19.63 -267.38 -227.10 -114.31 -267.38 160.56 24.45 -107.84 -107.84 -121.58 0.56 200.79 -121.58 -61.03 -122.30 212.27 -122.30 78.91 76.84 52.15 52.15 -19.93 192.00 69.98 -19.93 -6.70 90.16 91.33 -6.70 oct_test(): oct() returns a string that is the octal representation of an integer. i oct(i) 0 0o0 1 0o1 2 0o2 3 0o3 4 0o4 5 0o5 10 0o12 20 0o24 30 0o36 2019 0o3743 -11 -0o13 ord_test(): ord(c) returns the index of character c. String of characters: " Isn't this wonderful? ". ' I ' has character index 73 ' s ' has character index 115 ' n ' has character index 110 ' ' ' has character index 39 ' t ' has character index 116 ' ' has character index 32 ' t ' has character index 116 ' h ' has character index 104 ' i ' has character index 105 ' s ' has character index 115 ' ' has character index 32 ' w ' has character index 119 ' o ' has character index 111 ' n ' has character index 110 ' d ' has character index 100 ' e ' has character index 101 ' r ' has character index 114 ' f ' has character index 102 ' u ' has character index 117 ' l ' has character index 108 ' ? ' has character index 63 pow_test(): pow(a,b) returns a to the power b. a b pow(a,b) 2 3 8 2 -3 0.125 -2 3 -8 -2 -3 -0.125 3.14159 3 31.0063 3.14159 -3 0.0322515 2 3.14159 8.82498 pow(a,b,z) returns a to the power b, mod z. a b c pow(a,b,z) 10 3 3 1 10 3 5 0 10 3 7 6 range_test(): range(a,b) creates a range of integers from a to b-1. range(a,b,c) creates a range of integers from a to b-1 by increments of c. x=range(5,10) range(5, 10) 5,6,7,8,9, x=range(1,11,2) range(1, 11, 2) 1,3,5,7,9, x=range(11,1,-2) range(11, 1, -2) 11,9,7,5,3, x=range(10,20) = range(10, 20) y = (8 in x) is False len(x) = 10 reversed_test(): reversed(object) returns a "reversed" version of the object. x=range(5,10) 5 6 7 8 9 xr = reversed(x) 9 8 7 6 5 s='Matlab' M a t l a b sr = reversed(s) b a l t a M x = [ 10, 11, 12 ] 10 11 12 xr = reversed(x) 12 11 10 x = ( 10, 11, 12 ) 10 11 12 xr = reversed(x) 12 11 10 round_test(): round(x) rounds x to the nearest integral value. x round(x) -193.929743 -194.000000 118.630800 119.000000 -44.812458 -45.000000 80.679200 81.000000 53.509561 54.000000 -46.502989 -47.000000 87.712765 88.000000 -75.456982 -75.000000 -7.776314 -8.000000 -162.414567 -162.000000 round(x,ndigits) rounds x to n digits. x ndigits round(x,ndigits) 314.1592653590 0 314.0000000000 314.1592653590 1 314.2000000000 314.1592653590 2 314.1600000000 314.1592653590 3 314.1590000000 314.1592653590 4 314.1593000000 314.1592653590 5 314.1592700000 314.1592653590 6 314.1592650000 314.1592653590 7 314.1592654000 314.1592653590 8 314.1592653600 314.1592653590 9 314.1592653590 314.1592653590 10 314.1592653590 slice_test(): slice() creates an object represented by range(start:stop:increment) s: ' Abcdefghijklmnopqrstuvwxyz ' s[slice(0,10,2)]: Acegi s[slice(26,0,-3)]: zwtqnkheb s[slice(6)]: Abcdef sorted_test(): sorted(x) returns a sorted list x = [3, 1, 4, 6, 2] sorted(x) =( [1, 2, 3, 4, 6] sorted(x,reverse=True) =( [6, 4, 3, 2, 1] x = [1.23, 231.0, 31.2, 0.35] sorted(x) =( [0.35, 1.23, 31.2, 231.0] sorted(x,reverse=True) =( [231.0, 31.2, 1.23, 0.35] x = ['a', 'c', 'z', 'b', 'D'] sorted(x) =( ['D', 'a', 'b', 'c', 'z'] sorted(x,reverse=True) =( ['z', 'c', 'b', 'a', 'D'] x = Anaconda sorted(x) =( ['A', 'a', 'a', 'c', 'd', 'n', 'n', 'o'] sorted(x,reverse=True) =( ['o', 'n', 'n', 'd', 'c', 'a', 'a', 'A'] sum_test(): sum(x) computes the sum of entries sum( [5.0, 10.1, 15.2, 20.3] ) = 50.599999999999994 sum(x) can count Boolean True values sum( [False, True, True, False] ) = 2 sum(x,init) computes the sum of the entries plus init. sum( [5.0, 10.1, 15.2, 20.3] ,100) = 150.6 python_intrinsics_test: Normal end of execution. Tue May 20 22:25:36 2025