Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

python make a positive number negative code example

Example 1: get random number positive or negative python

import random
return 1 if random.random() < 0.5 else -1

Example 2: convert negative to positive in python

>>> n = -42
>>> -n       # if you know n is negative
42
>>> abs(n)   # for any n
42
>>> abs(-5.05)
5.05

Tags:

Python Example

Related

get current time using datetime python code example js code editor code example how to loop thouh enums c# code example what is root password in mysql code example funny programming comments code example php datetime in millis code example get the vector between two points unity code example c++ wait for any key ignore input code example set value input from javascript code example "" + variable java code example how to create a branch to work on github code example azure definition code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy