Python‎ > ‎Built-in‎ > ‎

float()

http://www.adilwaseem.com/

Introduction
The method will return the numeric value from the string written in single or double quote marks.

Syntax
float(x)

Parameters
x=number

Examples
The method returns the float value.
 >>> 
>>> float(21223)
21223.0

is_integer
The testing float value.
 >>> float.is_integer(22.00)
True
>>>

integer value to float
The method convert integer value to float.
 >>> int(33).__float__()
33.0


float(random.randrange()) and float(random.randint())  
The operator return with the pow(random.randrange(),random.randin()).
import operator
import random
a=float(random.randrange(1,10))
b=float(random.randint(20,40))
c=operator.pow(a,b)
if c.__le__(10):
    print("Random value: ",c+5)
elif c.__ge__(20):
    print("Random value: ",c-5)

float(input())
The input() value returns the math.sin(a)*2-1
import math
import operator
a=float(input("Please enter sine(value) : "))
b=math.sin(a).__mul__(2).__sub__(1)
print(b)
>>> 
Please enter sine(value) : 2.2
0.6169928076391802
>>>


float(input())
The equation value is determined through input().
import math
import operator
a=float(input("Please enter copysign(x) : "))
b=float(input("Please enter copysign(y) : "))

c=math.copysign(a,b).__add__(1.1).__mul__(math.acosh(2)).__truediv__(math.atan2(88,34))
print("The equation value is", c)

>>> 
Please enter copysign(x) : 2
Please enter copysign(y) : 6
The value is 3.3961966891396522
>>> 


class...: def....: if .....==float()
The class method executed the if statement.
import operator
class add_value:
    def __init__(self, a):
        self.a=a
        if self.a==float(a):
            print("The value:",self.a, ",is float:")
        else:
            print("Value accepted: ", self.a)
                  
                
value=3.134

add_value(value)

>>> 
The value: 3.134 ,is float:
>>>


The syntax open the input() into new default browser.
import webbrowser

x=input("Please enter your web address: ")

y=len(x)
z=float(y)

if z > 7:
    webbrowser.open_new_tab(x)
else:
    
>>> 
Please enter your web address: cnn.com
>>>

Comments