+ 3

Multilne exec()

How to use more than one line of code within exec()?

19th Jul 2018, 8:11 AM
Satyam
8 Antworten
+ 3
Have your tried to insert a newline char '\n'... Example: exec("print('hello')\nprint('world')")
19th Jul 2018, 8:33 AM
KrOW
KrOW - avatar
7th Mar 2019, 10:12 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 4
Thank you Rahul , Thank you once again KrOW !
19th Jul 2018, 11:40 AM
Satyam
+ 4
I just realized, using ; you can put two lines in one line! https://code.sololearn.com/cG3ArKeoYZAP/?ref=app
19th Jul 2018, 11:42 AM
Satyam
+ 3
Thank you KrOW. Your method worked!
19th Jul 2018, 8:41 AM
Satyam
+ 2
You can also separate them using ; (semicolon) like: exec("print('Hello') ; print(' World')")
19th Jul 2018, 10:22 AM
777
777 - avatar
+ 2
or use multiline strings: exec(''' print("hello") print("world") ''')
19th Jul 2018, 11:05 AM
KrOW
KrOW - avatar
+ 1
S. C. You are welcome 👍👍
19th Jul 2018, 8:50 AM
KrOW
KrOW - avatar