Machine Learning March 14, 2021 Python Comments Off on Python Numbers 5,122 Views
Number data types store numeric values. They are immutable data types, means that changing the value of a number data type results in a newly allocated object.
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Float, or “floating point number” is a number, positive or negative, containing one or more decimals.
Float can also be scientific numbers with an “e” to indicate the power of 10.
Complex numbers are written with a “j” as the imaginary part:
You can convert from one type to another with the int(), float(), and complex() methods:
Python defines a set of functions that are used to generate or manipulate random numbers. This particular type of functions are used in a lot of games, lotteries, OTP – (One Time Password), 2 Factor Authentication, Securtiy Lock or any application requiring random number generation.
1. random() :- This number is used to generate a float random number less than 1 and greater or equal to 0.
2. randint(start, end) :- This function is also used to generate random number but within a range specified in its arguments.
3. randrange(start, end, step) :- This function is also used to generate random number but within a range specified in its arguments.
4. uniform(a, b) :- This function is used to generate a floating point random number between the numbers mentioned in its arguments.
5. choice() :- This function is used to generate 1 random number from a container.
6. shuffle() :- This function is used to shuffle the entire list to randomly arrange them.
7. sample() :- This function Returns randomly selected items from a sequence
8. seed(): :- This function takes a number as a parameter called the seed and produces same random numbers each time you call this function with that number.
you can also import python module as
Note : import selected module from python random package
Note : import all the random modules as