<jupyter_start><jupyter_text>Extra stuff for later notebooks  2. Once more about functions 1. Built-in functions2. Functions generated by you3. Functions imported from modules  1. Built-in functions<jupyter_code>A = (5, -1, -15, 25, 2)
sorted(A)
sorted((5, -1, -15, 25, 2))
sorted(A, reverse= True)
help(sorted)
sorted(A, key=abs)
sorted?
print('Hello', 'Hello')
print('Hello', 'Hello', sep='*****')
help(print)<jupyter_output>Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.<jupyter_text>2. Your own functions  Please note that variable name format with _underscores_.This is the first use of `indentation` during our journey<jupyter_code># defining the function

def my_first_function(a, b):
    return a + b
# calling the function

my_first_function(10, 5)
A = my_first_function(20, 100)
A<jupyter_output><empty_output><jupyter_text>Function with default parameters<jupyter_code>def my_second_function(a, b = 100):
    return a + b
my_second_function(5)
my_second_function(5, 20)<jupyter_output><empty_output><jupyter_text>Not all functions have arguments<jupyter_code>def my_third_function():
    return 10
my_third_function()<jupyter_output><empty_output><jupyter_text>Functions can do something else rather than returning a value<jupyter_code>def my_third_function(a):
    print(a)
my_third_function('Hello world')<jupyter_output>Hello world<jupyter_text>Let us see what happens if we assign the call to a variable_This is difficult to understand - do not be put off by this_<jupyter_code>A = my_third_function('Hello world')
A<jupyter_output><empty_output><jupyter_text>3. Functions imported from modules  4. Reading in text data<jupyter_code>f_handle = open('data/karamazov_brothers.txt', 'r')
text = f_handle.read()
f_handle.close()
len(text)
text[:10000]
print(text[:10000])
print(text[5016:10000])
txt_list = text.split(' ')
len(txt_list)
txt_list[1000:1100]
print(txt_list[1000:1100])
txt_list.count('an')
txt_list.count('Fyodor')
txt_list.count('Ivan')
txt_list.count('enigmatic')<jupyter_output><empty_output><jupyter_text>4. Reading in and manipulating tabular data  5. Reading in images<jupyter_code># importing matplotlib module 
import matplotlib.image as mpimg 

img = mpimg.imread('data/newborn_heart_image.jpg') 
img.ndim
img.shape
369 * 636 * 3
img.flatten()
len(img.flatten())
print(set(img.flatten()))
img[:, :, 1]
img[:, :, 2]
img[1, :, :]
# Output Image

# importing matplotlib module 
import matplotlib.pyplot as plt 

plt.imshow(img)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup