{"id":25355,"date":"2021-11-10T09:38:11","date_gmt":"2021-11-10T04:08:11","guid":{"rendered":"https:\/\/python-programs.com\/?p=25355"},"modified":"2021-11-10T09:38:11","modified_gmt":"2021-11-10T04:08:11","slug":"python-math-log10-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-math-log10-method-with-examples\/","title":{"rendered":"Python math.log10() Method with Examples"},"content":{"rendered":"
math.log10() Method in Python:<\/strong><\/p>\n The math.log10() method returns a number’s base-10 logarithm.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n x:<\/strong> This is Required. Specifies the value for which the logarithm should be calculated.<\/p>\n Return Value:<\/strong><\/p>\n Returns a float value that represents a number’s base-10 logarithm.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n math.log10() Method in Python: The math.log10() method returns a number’s base-10 logarithm. Syntax: math.log10(x) Parameters x: This is Required. Specifies the value for which the logarithm should be calculated. If the value is 0 or a negative number, a ValueError is returned. If the value is not a number, a TypeError is returned. Return Value: …<\/p>\nmath.log10(x)<\/pre>\n
\n
Given Number = 4\r\nGiven List = [2, 3.5, 4, 5.62, 1]<\/pre>\n
The base-10 logarithm of a given number { 4 } = 0.6020599913279624\r\nThe base-10 logarithm of a list element gvn_lst[1] = 0.5440680443502757<\/pre>\n
Given Number = 2\r\nGiven List = [8, 2, 9, 1, 0]<\/pre>\n
The base-10 logarithm of a given number { 2.0 } = 0.3010299956639812\r\nThe base-10 logarithm of a list element gvn_lst[2] = 0.9542425094393249<\/pre>\n
math.log10() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = [2, 3.5, 4, 5.62, 1]\r\n# Give the number as static input and store it in another variable.\r\ngvn_numb = 4\r\n# Apply math.log10() method to the given number to get base-10 logarithm of a\r\n# given number.\r\n# Store it in another variable.\r\nrslt1 = math.log10(gvn_numb)\r\n# Print the above result.\r\nprint(\"The base-10 logarithm of a given number {\", gvn_numb, \"} =\", rslt1)\r\n# Apply math.log10() method to the given list to get base-10 logarithm of a list\r\n# element.\r\n# Store it in another variable.\r\nrslt2 = math.log10(gvn_lst[1])\r\n# Print the base-10 logarithm of a given list element.\r\nprint(\"The base-10 logarithm of a list element gvn_lst[1] =\", rslt2)\r\n<\/pre>\n
The base-10 logarithm of a given number { 4 } = 0.6020599913279624\r\nThe base-10 logarithm of a list element gvn_lst[1] = 0.5440680443502757<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(int, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give the number as user input using the float(input()) function and \r\n# store it in another variable.\r\ngvn_numb = float(input(\"Enter some random number = \"))\r\n# Apply math.log10() method to the given number to get base-10 logarithm of a\r\n# given number.\r\n# Store it in another variable.\r\nrslt1 = math.log10(gvn_numb)\r\n# Print the above result.\r\nprint(\"The base-10 logarithm of a given number {\", gvn_numb, \"} =\", rslt1)\r\n# Apply math.log10() method to the given list to get base-10 logarithm of a list\r\n# element.\r\n# Store it in another variable.\r\nrslt2 = math.log10(gvn_lst[2])\r\n# Print the base-10 logarithm of a given list element.\r\nprint(\"The base-10 logarithm of a list element gvn_lst[2] =\", rslt2)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 8 2 9 1 0\r\nEnter some random number = 2 \r\nThe base-10 logarithm of a given number { 2.0 } = 0.3010299956639812\r\nThe base-10 logarithm of a list element gvn_lst[2] = 0.9542425094393249<\/pre>\n","protected":false},"excerpt":{"rendered":"