>>> code = """for i in range(5):\n print('Hello world!')""" >>> exec(code) Hello world! Hello world! Hello world! Hello world! Hello world!