xxxxxxxxxx
#Float or int like this - 2.6, 5.7, 1.89 etc
a = 90.7
print(a, 'is a float')
xxxxxxxxxx
positive_infinity = float('inf')
negative_infinity = float('-inf')
# Checking if a value is infinity
x = 10
if x == positive_infinity:
print("x is positive infinity")
elif x == negative_infinity:
print("x is negative infinity")
else:
print("x is not infinity")
# Mathematical operations with infinity
y = 5
# Adding infinity to a finite value
result = positive_infinity + y
print(result) # Output: inf
# Subtracting infinity from a finite value
result = negative_infinity - y
print(result) # Output: -inf
# Comparing two infinity values
if positive_infinity > negative_infinity:
print("Positive infinity is greater than negative infinity")
xxxxxxxxxx
# Assigning infinity to a variable
my_infinity = float('inf')
# Printing the value of infinity
print(my_infinity)
# Performing operations with infinity
print(my_infinity + 10) # Output: inf
print(my_infinity * 2) # Output: inf
print(my_infinity / 2) # Output: inf
# Comparing infinity with other numbers
print(my_infinity > 100) # Output: True
print(my_infinity < 0) # Output: False
xxxxxxxxxx
# Check documentation info
print(sys.float_info)
# Example
x = 1.2
print(type(x))
xxxxxxxxxx
# Floats are basically decimal numbers
# Make sure you don't mix Floats with Ints (Integers)
# For example (a float):
list_of_floats = [2.4, 99.99, 12.4444448812827122151]
# For example (an int):
list_of_ints = [1, 491, 1821, 2198, 128]
# If you have a mental breakdown and you can't find the difference between them
# Just use the type() method/function
# Example:
print(type(2.9))
print(type(751))
xxxxxxxxxx
x = 3
y = 4.5
result = float(x) + y #The float() is on x because it is not a decimal point.
print(result)
#Make sure you put the float() function on variables that are intergers
xxxxxxxxxx
Command: float()
What is float: Float Conversion Function
Description: The float() function converts a given value to a floating-point number data type.
Example: floating_number = float("42.5") will convert the string "42.5" to the float 42.5.