+ 3
Multilne exec()
How to use more than one line of code within exec()?
8 Respuestas
+ 3
Have your tried to insert a newline char '\n'... Example:
exec("print('hello')\nprint('world')")
+ 6
Summarizing:
https://code.sololearn.com/c0ocwjEY16AF/?ref=app
+ 4
I just realized, using ; you can put two lines in one line!
https://code.sololearn.com/cG3ArKeoYZAP/?ref=app
+ 3
Thank you KrOW. Your method worked!
+ 2
You can also separate them using ; (semicolon) like:
exec("print('Hello') ; print(' World')")
+ 2
or use multiline strings:
exec('''
print("hello")
print("world")
''')
+ 1
S. C. You are welcome 👍👍