Multiple commands | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Multiple commands

can we use multiple commands at once in Python like adding and subtracting will be given in two separate lines but I want the answers after the two commands which I give

2nd Nov 2016, 3:26 PM
Jude Felix
Jude Felix - avatar
2 Answers
+ 1
Guesses: 1. Separate same-line commands with semicolon: >>> a,b,c=1,2,3; p,m=a+b,c-b; print(p,m) 3 1 2. Use a script file (saved from a text editor) script.py: a=1 b=2 c=3 p=a+b m=c-b print(p, m) Windows/Linux C:\>python script.py / $ python script.py 3 1 3. Use threads for simultaneous execution (Python is not thread-safe by default!) 4. You're asking if Python maintains state. That's what variables do; they store things for later use, so: Yes...as long as the process doesn't exit.
5th Nov 2016, 10:34 AM
Kirk Schafer
Kirk Schafer - avatar
0
I don't really understand what you mean. Do you want to split a long statement in two lines while maintaining its integrity? In this case use a backslash like this: print(7+8\ -5)
3rd Nov 2016, 12:49 AM
Anastasios Glaros
Anastasios Glaros - avatar