Syntax error in function but everything seems correct I am custom defining a function and following is my function but I get error as below
def  saveSlice(img, fname, path):
     img  = np.uint8(img * 255)
     fout = os.path.join(path, f'{fname}.png')
     cv2.imwrite(fout, img)
     print(f'[+] Slice saved: {fout}', end='\r')


I get error message as below
File &quot;ipython-input-79-e8d731623c8b&quot;, line 3
fout = os.path.join(path, f'{fname}.png')
                                                                           ^

SyntaxError: invalid syntax
What am I doing wrong?
If you use Python earlier than 3.6 f-strings are not available, and that code has an incorrect syntax. In that case you can use the format method of the strings instead like that (2 lines are modified):
def  saveSlice(img, fname, path):
     img  = np.uint8(img * 255)
     fout = os.path.join(path, '{}.png'.format(fname))
     cv2.imwrite(fout, img)
     print('[+] Slice saved: {}'.format(fout), end='\r')