{"id":24544,"date":"2021-10-21T10:06:24","date_gmt":"2021-10-21T04:36:24","guid":{"rendered":"https:\/\/python-programs.com\/?p=24544"},"modified":"2021-11-05T19:38:17","modified_gmt":"2021-11-05T14:08:17","slug":"python-chr-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-chr-function-with-examples\/","title":{"rendered":"Python chr() function with Examples"},"content":{"rendered":"
In the previous article, we have discussed Python Program for compile() Function<\/a> The character that represents the specified unicode is returned by the chr() function.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n number:<\/strong> It is an integer. A valid Unicode code point is represented by an integer.<\/p>\n The integer has a valid range of 0 to 1,114,111.<\/p>\n Return value:<\/strong><\/p>\n Returns a character (string) with the integer as its Unicode code point.<\/p>\n If the integer falls outside of the range, a ValueError will be thrown.<\/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 Find a Comprehensive Collection of Python Built in Functions<\/a> that you need to be aware of and use them as a part of your program.<\/p>\n In the previous article, we have discussed Python Program for compile() Function chr() Function in Python: The character that represents the specified unicode is returned by the chr() function. Syntax: chr(number) Parameters number: It is an integer. A valid Unicode code point is represented by an integer. The integer has a valid range of 0 …<\/p>\n
\nchr() Function in Python:<\/strong><\/p>\nchr(number)<\/pre>\n
Given first number = 68\r\nGiven second number = 101<\/pre>\n
The character that represents the given unicode 68 = D\r\nThe character that represents the given unicode 101 = e<\/pre>\n
Given first number = 99\r\nGiven second number = 75<\/pre>\n
The character that represents the given unicode 99 = c\r\nThe character that represents the given unicode 75 = K<\/pre>\n
Program for chr() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\ngvn_numb1 = 68\r\n# Apply chr() function to the given number and store it in another variable.\r\nrslt_charctr1 = chr(gvn_numb1)\r\n# Print the character that represents the given Unicode.\r\nprint(\"The character that represents the given unicode\",\r\n gvn_numb1, \"=\", rslt_charctr1)\r\n# Similarly, do the same for the other number and print the result.\r\ngvn_numb2 = 101\r\nrslt_charctr2 = chr(gvn_numb2)\r\nprint(\"The character that represents the given unicode\",\r\n gvn_numb2, \"=\", rslt_charctr2)\r\n<\/pre>\n
The character that represents the given unicode 68 = D\r\nThe character that represents the given unicode 101 = e<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the number as user input using the int(input()) function \r\n# and store it in a variable.\r\ngvn_numb1 = int(input(\"Enter some random number = \"))\r\n# Apply chr() function to the given number and store it in another variable.\r\nrslt_charctr1 = chr(gvn_numb1)\r\n# Print the character that represents the given Unicode.\r\nprint(\"The character that represents the given unicode\",\r\n gvn_numb1, \"=\", rslt_charctr1)\r\n# Similarly, do the same for the other number and print the result.\r\ngvn_numb2 = int(input(\"Enter some random number = \"))\r\nrslt_charctr2 = chr(gvn_numb2)\r\nprint(\"The character that represents the given unicode\",\r\n gvn_numb2, \"=\", rslt_charctr2)\r\n<\/pre>\n
Enter some random number = 500\r\nThe character that represents the given unicode 500 = \u01f4\r\nEnter some random number = 75\r\nThe character that represents the given unicode 75 = K<\/pre>\n
\n