from io import StringIO # create a StringIO object with a string my_string = "This is a test string." string_io_obj = StringIO(my_string) # read from the StringIO object print(string_io_obj.read()) # write to the StringIO object string_io_obj.write(" Another string to add.") string_io_obj.seek(0) # read again to see the updated string print(string_io_obj.read())In this example, we create a StringIO object and use it to read and write strings. We first create a StringIO object using the `io.StringIO()` function with an initial string passed as an argument. We then read from the StringIO object using the `read()` function and print the output to the console. Next, we write a new string to the StringIO object using the `write()` function and then use the `seek()` function to move the cursor back to the beginning of the stream so we can read the updated string using the `read()` function again. Overall, the StringIO library provides a convenient way to manipulate in-memory strings using a file-like interface.