{"id":25556,"date":"2021-11-23T08:56:46","date_gmt":"2021-11-23T03:26:46","guid":{"rendered":"https:\/\/python-programs.com\/?p=25556"},"modified":"2021-11-23T08:56:46","modified_gmt":"2021-11-23T03:26:46","slug":"python-string-isascii-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-isascii-method-with-examples\/","title":{"rendered":"Python String isascii() Method with Examples"},"content":{"rendered":"
String isascii() Method in Python:<\/strong><\/p>\n If all of the characters are ASCII, the isascii() method returns True (a-z). Otherwise returns False.<\/p>\n Syntax:\u00a0<\/strong><\/p>\n Parameters: <\/strong>This method has no parameters.<\/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 For any non-ASCII characters, the isascii() method returns False.<\/p>\n For Example:<\/strong><\/p>\n Output:<\/strong><\/p>\n The isascii() method also verifies ASCII Unicode characters.<\/p>\n For Example:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n String isascii() Method in Python: If all of the characters are ASCII, the isascii() method returns True (a-z). Otherwise returns False. Syntax:\u00a0 string.isascii() Parameters: This method has no parameters. Examples: Example1: Input: Given string = “hello@%btechgeeks670” Output: True Example2: Input: Given string = ‘\u00df’ Output: False String isascii() Method with Examples in Python Using Built-in …<\/p>\nstring.isascii()<\/pre>\n
Given string = \"hello@%btechgeeks670\"<\/pre>\n
True<\/pre>\n
Given string = '\u00df'<\/pre>\n
False<\/pre>\n
String isascii() Method with 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_str = \"btechgeeks789@\"\r\n# Apply isascii() method on the given string where if all of the characters are\r\n# ASCII, the isascii() method returns True (a-z). Otherwise returns False.\r\n# Store it in a variable.\r\nrslt = gvn_str.isascii()\r\n# Print the result after applying isascii() method on the given string.\r\nprint(rslt)\r\n<\/pre>\n
True\r\n<\/pre>\n
# A letter in German\r\ngvn_str = '\u00df'\r\nprint(gvn_str.isascii())\r\n\r\ngvn_str = '\u00f5'\r\nprint(gvn_str.isascii())\r\n\r\ngvn_str = '\u00c5'\r\nprint(gvn_str.isascii())\r\n<\/pre>\n
False\r\nFalse\r\nFalse<\/pre>\n
gvn_str = '\/u0000' # Null Unicode\r\nprint(gvn_str.isascii())\r\n\r\ngvn_str = '\/u007f' # DEL Unicode\r\nprint(gvn_str.isascii())\r\n\r\ngvn_str = '\/u0041' # A's Unicode\r\nprint(gvn_str.isascii())\r\n\r\ngvn_str = '\/u0061' # a's Unicode\r\nprint(gvn_str.isascii())\r\n\r\n<\/pre>\n
True\r\nTrue\r\nTrue\r\nTrue<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the string as user input using the input() function and store it in a variable.\r\ngvn_str = input(\"Enter some random string = \")\r\n# Apply isascii() method on the given string where if all of the characters are\r\n# ASCII, the isascii() method returns True (a-z). Otherwise returns False.\r\n# Store it in a variable.\r\nrslt = gvn_str.isascii()\r\n# Print the result after applying isascii() method on the given string.\r\nprint(rslt)<\/pre>\n
Enter some random string = hello@%btechgeeks670\r\nTrue<\/pre>\n","protected":false},"excerpt":{"rendered":"