Есть ли способ выполнить несколько операторов при выполнении их в одной строке, например:
import time
print ("Ok, I know how to write programs in Python now.")
time.sleep(0.5)
print (".") # This should print on the same line as the previous print statement.
time.sleep(0.5)
print (".") # ... As should this one
... Таким образом, выход должен быть:
Ok, I know how to write programs in Python now.*.*.
* Ожидает .5 секунд
Вы также сможете сделать это с помощью синтаксиса end="".
print("this ",end="")
print("will continue on the same line")
print("but this wont")
Вернет
this will continue on the same line
but this wont
, поэтому следующее будет работать.
import time
print ("Ok, I know how to write programs in Python now.",end="")
time.sleep(0.5)
print (".",end="") # This should print on the same line as the previous print statement.
time.sleep(0.5)
print (".") # ... As should this one
Разве это не проще?:
import time
print ("Ok, I know how to write programs in Python now."),
time.sleep(0.5)
print ("."), # This should print on the same line as the previous print statement.
time.sleep(0.5)
print (".") # ... As should this one
Можно ли это сделать и с входами?
print("THIS IS A TEST AREA")
print()
print("TETST OF SAME LINE INTERACTION")
print("X: ", end="") #This works Fine
input("")
time.sleep(0.5) #This however dew to python3 wont?
print(" STAR")
Этот вывод выглядит так ...
THIS IS A TEST AREA
TETST OF SAME LINE INTERATION
X:
STAR
>>>