{"id":12052,"date":"2021-11-18T05:34:13","date_gmt":"2021-11-18T05:34:13","guid":{"rendered":"https:\/\/linuxways.net\/?p=12052"},"modified":"2024-03-25T02:10:45","modified_gmt":"2024-03-25T02:10:45","slug":"python-ord-function","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/scripting\/python-ord-function\/","title":{"rendered":"Python ord() function"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>ord() function in Python prints out the Unicode code of a specified character. This function also accepts a string as an argument and prints out the corresponding Unicode code of that string. The Unicode code point is represented by an integer when the value of the variable is a Unicode object or corresponding byte value.<\/p>\n<p>And we will show you how to use the ord() function in Python as you go through it below. Hope you understand.<\/p>\n<h2>Example<\/h2>\n<pre>\r\nx = ord(\"b\")\r\n\r\nprint(x)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>98<\/strong><\/pre>\n<h2>Definition<\/h2>\n<p>The ord() function has a function that returns the Unicode representing the specified argument.<\/p>\n<h2>The syntax<\/h2>\n<pre>\r\nord(character)\r\n<\/pre>\n<p><strong>Parameter Values<\/strong>:<\/p>\n<pre>\r\ncharacter: any word, string\r\n<\/pre>\n<h2>More examples<\/h2>\n<p><strong>Example 1<\/strong>: Basic ord() function<\/p>\n<pre>\r\nx = ord(\"B\")\r\n\r\nprint(x)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>66<\/strong>\r\n<\/pre>\n<p><strong>Example 2<\/strong>: Enter a word and print out the Unicode of that word<\/p>\n<pre>\r\nprint(\"Enter the word:\")\r\n\r\nx = input()\r\n\r\ny = ord(x)\r\n\r\nprint(\"Unicode:\",y)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>Enter the word: t<\/strong>\r\n\r\n<strong>Unicode: 116<\/strong>\r\n<\/pre>\n<p>Example 3: The program will be an error if the string length is not equal to 1<\/p>\n<pre>\r\nx = ord('BC')\r\n\r\nprint(x)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>---------------------------------------------------------------------------<\/strong>\r\n\r\n<strong>TypeError<\/strong> Traceback (most recent call last)\r\n\r\n<strong>Untitled-1<\/strong> in\r\n\r\n<strong>----&gt; 1 <\/strong>x <strong>=<\/strong> ord<strong>('BC')<\/strong>\r\n\r\n2 print<strong>(<\/strong>x<strong>)<\/strong>\r\n\r\n<strong>TypeError<\/strong>: ord() expected a character, but string of length 2 found\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>Above is the tutorial about how to use the ord() function in Python through examples.<\/p>\n<p>Thanks for reading!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction ord() function in Python prints out the Unicode code of a specified character. This function also accepts a string as an argument and prints out the corresponding&hellip;<\/p>","protected":false},"author":110,"featured_media":12063,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[10],"class_list":["post-12052","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-python"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/12052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=12052"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/12052\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/12063"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=12052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=12052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=12052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}