⊗pyPmBsNN 17 of 208 menu

Negative Numbers in Python

Numbers can be negative. To do this, you need to put a minus sign before the number:

num = -1 print(num) # -1

The minus sign can be written both for numbers and for variables:

num1 = 1 num2 = -num1 # wrote the contents of num1 with the opposite sign to num2 print(num2) # -1

Or like this:

num = 1 print(-num) # -1

Create a variable test with the value -100. Print this value to the console.

Create a variable test, write some positive or negative number into it. Output this number with the opposite sign to the console.

Let's say you have a variable test with a negative number. Subtract -20 from it. Print the result to the console.

byenru