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
2 Réponses
+ 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.
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)