P
P
piffo2020-08-03 23:16:32
Python
piffo, 2020-08-03 23:16:32

If statement in python?

I am learning python from the book A Byte of Python. There are lines of code like this

if os.system(zip_command) == 0:
    print("Резервная копия успешно создана в", target)
else:
    print("Создание резервной копии НЕ УДАЛОСЬ")

1. Do I understand correctly that the os.system function is equivalent to the fact that I would enter this command on the command line?
2. I do not quite understand how exactly we launch this function. Didn't we just check the condition with this code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2020-08-04
@piffo

1. Yes, that's about it.
2. The condition says "the result of the function execution is compared with zero". To find out the result of the execution, the function must be executed. So the command will definitely start.

D
Dimonchik, 2020-08-03
@dimonchik2013

listen, don’t worry,
take an IDE and write the code, the
alignment there is like this - if you managed to run something in the line, then return 0, otherwise the error is,
and what’s there and how is it in the line - you won’t know in any way, to find out - other commands - that is, you let it go and it fell out in a second - it still returned 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question