{"id":24612,"date":"2021-10-23T09:09:43","date_gmt":"2021-10-23T03:39:43","guid":{"rendered":"https:\/\/python-programs.com\/?p=24612"},"modified":"2021-11-05T19:13:43","modified_gmt":"2021-11-05T13:43:43","slug":"python-string-isspace-method-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-isspace-method-examples\/","title":{"rendered":"Python String isspace() Method with Examples"},"content":{"rendered":"
In the previous article, we have discussed Python String isprintable() Method Examples<\/a> If the string contains only whitespace characters, the isspace() method returns True. If it does not, it returns False.<\/p>\n Whitespace characters are characters that are used for spacing. For example, tabs, spaces, newlines, and so on.<\/p>\n Syntax:<\/strong><\/p>\n Parameters: <\/strong>This function has no parameters.<\/p>\n Return Value:<\/strong><\/p>\n The isspace() method gives:<\/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 Are you facing difficulties in finding all the methods that a string object can call in python? Have a glance at this Python String Method Examples<\/a> Tutorial & meet such challenges with ease.<\/p>\n In the previous article, we have discussed Python String isprintable() Method Examples isspace() Method in Python: If the string contains only whitespace characters, the isspace() method returns True. If it does not, it returns False. Whitespace characters are characters that are used for spacing. For example, tabs, spaces, newlines, and so on. Syntax: string.isspace() Parameters: …<\/p>\n
\nisspace() Method in Python:<\/strong><\/p>\nstring.isspace()<\/pre>\n
\n
Given string = ' Python-programs '\r\nGiven string = ' \\t'\r\nGiven string = ''<\/pre>\n
The given string = Python-programs \r\nChecking if the given string is has whitespace or not = False\r\nThe given string = \t\r\nChecking if the given string is whitespace or not = True\r\nThe given string = \r\nChecking if the given string is whitespace or not = False<\/pre>\n
Given string = 'welcome to python programs'\r\nGiven string = '\\t \\t'\r\nGiven string = 'hellobtechgeeks'<\/pre>\n
The given string = welcome to python programs\r\nChecking if the given string is has whitespace or not = False\r\nThe given string = \t \t\r\nChecking if the given string is whitespace or not = True\r\nThe given string = hellobtechgeeks\r\nChecking if the given string is whitespace or not = False<\/pre>\n
String isspace() Method Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the string as static input and store it in a variable.\r\ngvn_strng1 = ' Python-programs '\r\n# Apply isspace() function to the given string in which if the string\r\n# contains only whitespace characters, the isspace() method returns True.\r\n# If it does not, it returns False.\r\n# Store it in another variable.\r\nrslt_1 = gvn_strng1.isspace()\r\n# Print the above-given String.\r\nprint(\"The given string = \", gvn_strng1)\r\n# Print the result after checking if the given string has only whitespace\r\n# characters or not.\r\nprint(\"Checking if the given string is has whitespace or not = \", rslt_1)\r\n# Similarly, do the same for other strings and print the result.\r\ngvn_strng2 = ' \\t'\r\nrslt_2 = gvn_strng2.isspace()\r\nprint(\"The given string = \", gvn_strng2)\r\nprint(\"Checking if the given string is whitespace or not = \", rslt_2)\r\n\r\ngvn_strng3 = ''\r\nrslt_3 = gvn_strng3.isspace()\r\nprint(\"The given string = \", gvn_strng3)\r\nprint(\"Checking if the given string is whitespace or not = \", rslt_3)\r\n<\/pre>\n
The given string = Python-programs \r\nChecking if the given string is has whitespace or not = False\r\nThe given string = \t\r\nChecking if the given string is whitespace or not = True\r\nThe given string = \r\nChecking if the given string is whitespace or not = False<\/pre>\n
\n