1. How to check that the file exists?
  2. How to append a text to the file?

I know how to create the file, but in this case, it overwrites all data:

import io

with open('text.txt', 'w', encoding='utf-8') as file:
    file.write('text!')

In *nix I can do something like:

#!/bin/sh

if [ -f text.txt ]
    #If the file exists - append text
    then echo 'text' >> text.txt; 

    #If the file doesn't exist - create it
    else echo 'text' > text.txt;  
fi;
Edit
Report