Tue Oct 19 17:02:21 2021 python_intrinsics_test(): Python version: 3.6.9 Test python_intrinsics(). abs_test abs() returns the absolute value of a number. x abs(x) -36.726636 36.726636 -127.427960 127.427960 75.686769 75.686769 -65.031799 65.031799 112.711646 112.711646 -1.002416 1.002416 212.736764 212.736764 6.923743 6.923743 -156.211538 156.211538 63.034025 63.034025 -2347553 2347553 24917610 24917610 -89754720 89754720 -22141494 22141494 22024557 22024557 50138477 50138477 -77326935 77326935 43816158 43816158 -62342768 62342768 87632790 87632790 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__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__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 179 90 1 89 134 87 1 47 325 -55 -6 -5 361 4 90 1 865 -21 -42 -17 -912 -68 13 -28 738 74 9 72 795 -62 -13 -11 -111 -45 2 -21 -463 -98 4 -71 108.718612 -2.157319 -51.000000 -1.304671 82.566967 -12.823573 -7.000000 -7.198042 -17.543143 16.975430 -2.000000 16.407717 -48.374978 -3.360345 14.000000 -1.330142 30.143248 10.426316 2.000000 9.290615 -23.373862 -10.219140 2.000000 -2.935582 122.573310 8.565092 14.000000 2.662017 75.545528 -10.206462 -8.000000 -6.106166 44.033699 -13.634584 -4.000000 -10.504638 155.472881 1.546940 100.000000 0.778835 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__': 'python_intrinsics_test.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7fd8cf0b2d30>, '__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' -9126730924804211577 ' abcde' 5705781398955812944 ' 12345' -4875476442643206359 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)= 140569163621960 b = 3 id(b)= 10914560 c = Hallelujah! id(c)= 140569137905776 d = [1 2 3] id(d)= 140568038747392 e = id_test, id(e) = 140569139417296 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) -926 484 484 107 -387 107 -350 -462 -350 406 646 646 578 -230 578 197 -815 197 287 -774 287 858 -821 858 -83 -48 -48 440 -339 440 max(a) returns the maximum element of a. a1 a2 a3 max(a) -773 900 -748 900 -416 582 179 582 -324 803 -280 803 -508 819 934 934 -790 -913 -569 -569 952 -27 -423 952 -727 -301 -860 -301 937 528 -757 937 170 969 -386 969 -978 -414 -570 -414 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.14 7.48 -30.14 -78.33 -111.76 -111.76 -62.96 56.11 -62.96 -47.46 96.80 -47.46 214.44 61.65 61.65 53.13 -46.70 -46.70 -150.75 -7.27 -150.75 123.74 -38.17 -38.17 46.49 60.25 46.49 -81.80 96.45 -81.80 min(a) returns the minimum element of a. a1 a2 a3 min(a) -14.41 -174.02 -12.26 -174.02 232.68 -88.65 7.22 -88.65 185.06 -206.34 0.80 -206.34 -47.65 -0.05 -8.54 -47.65 62.98 46.74 106.65 46.74 -286.87 -55.25 -53.33 -286.87 206.47 -46.26 -23.31 -46.26 -79.57 147.73 -146.17 -146.17 -97.40 99.27 -73.61 -97.40 86.82 -72.26 -10.36 -72.26 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) 19.721829 20.000000 -29.121542 -29.000000 40.944479 41.000000 -110.805985 -111.000000 15.503911 16.000000 78.407267 78.000000 -17.285239 -17.000000 -195.310118 -195.000000 22.165743 22.000000 96.858496 97.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 The slice() function 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 Demonstrate the sorted function. 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 Demonstrate the sum function. 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 Oct 19 17:02:21 2021