devxlogo

February 22, 2020

Check for finite numbers in Python

Use the math module???s isfinite method to determine if a value is finite or not.  If it is not a number, the function returns false.  See below for an example:math.isfinite(10) returns True

How to detect Python version at runtime

At times, we want to run our code only if the version of Python engine is above a certain version. See below for sample code. Import sysversion = sys.version

Return multiple values from a function in python

Python can return multiple values at a time. See below for a simple example. def multipleValueFunc():     z = 11     b = 22    return z, b  j,k  = multipleValueFunc () print(j, k) 

Reverse a string in Python

Its pretty ease to reverse a string in Python. ???Devx Jan???[::-1]  gives ???naJ xveD???