isdigit(): checking digits only in a string in Python

Use the isdigit() method to check if a string only contains digits. Digits include numbers from 0 to 9 and also superscripts and subscripts. word = '32' print(word.isdigit()) #output: True print("\u2083".isdigit()) #unicode for subscript 3 #output: True word = 'beach'…

isnumeric(): checking numerics only in a string in Python

Use the isnumeric() method to check if a string only contains numeric chars. Numerics include numbers from 0 to 9 and combinations of them, roman numerals, superscripts, subscripts, fractions, and other variations. word = '32' print(word.isnumeric()) #output: True print("\u2083".isnumeric()) #unicode…

How to swap two variables in Python

In this post I will show how to swap the values of two variables. The first way is very common in many languages and require the use of a third variable. The second and recommended way is what they call…