{"id":7239,"date":"2020-01-08T23:33:26","date_gmt":"2020-01-08T18:03:26","guid":{"rendered":"https:\/\/tutorials.eyehunts.com\/?p=7239"},"modified":"2021-08-30T18:40:55","modified_gmt":"2021-08-30T13:10:55","slug":"convert-string-to-bytes-python-bytes-encode-method","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/","title":{"rendered":"Convert string to bytes Python | bytes &#038; encode method"},"content":{"rendered":"\n<p>To <strong>convert string to bytes in Python<\/strong>, you have to use a <strong>bytes() method or encode()&nbsp;function<\/strong>. A bytes() method returns a bytes object which is immutable (value can&#8217;t be modified). If you want a mutable value then use&nbsp;bytearray()&nbsp;method.<\/p>\n\n\n\n<p><a href=\"https:\/\/tutorial.eyehunts.com\/\/python\/python-strings-tutorial-example\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"String (opens in a new tab)\">String<\/a> to bytes is more popular these days due to the fact that for handling files or Machine Learning ( Pickle File ).<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Methods to convert string to bytes<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>bytes(str, enc)<\/strong><\/li><li><strong>encode(enc)<\/strong><\/li><\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Examples: \u00a0Using\u00a0<code>encode(enc)<\/code><\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. To convert a string to bytes.<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>str = \"Hello\"  # string\n\nprint(str, type(str))\n\ndata = str.encode()  # bytes\n\nprint(data,type(data))<\/code><\/pre>\n\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"161\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png?resize=300%2C161&#038;ssl=1\" alt=\"convert a string to bytes encode\" class=\"wp-image-7250\" srcset=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode.png?resize=300%2C161&amp;ssl=1 300w, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode.png?w=704&amp;ssl=1 704w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. To convert bytes to a String.<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>byt = b\"Hello\"  # bytes\n\nprint(byt, type(byt))\n\ndata = byt.decode()  # string\n\nprint(data,type(data))\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"161\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-bytes-to-a-String-decode-300x161.png?resize=300%2C161&#038;ssl=1\" alt=\"convert bytes to a String decode\" class=\"wp-image-7251\" srcset=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/01\/convert-bytes-to-a-String-decode.png?resize=300%2C161&amp;ssl=1 300w, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/01\/convert-bytes-to-a-String-decode.png?w=704&amp;ssl=1 704w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Examples: &nbsp;Using&nbsp;bytes<code>(enc)<\/code><\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>msg = \"Python is best\"\n\n# printing original string  \nprint(\"The original string : \" + str(msg))\n\n# Using bytes(str, enc) \n# convert string to byte  \nres = bytes(msg, 'utf-8')\n\n# print result \nprint(\"The byte converted string is  : \" + str(res) + \", type : \" + str(type(res))) <\/code><\/pre>\n\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The original string: Python is best<br> The byte converted string is: b&#8217;Python is best&#8217;, type : <\/p><\/blockquote>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>More Examples:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_str = \"hello world\"\nmy_str_as_bytes = str.encode(my_str)\ntype(my_str_as_bytes) # ensure it is byte representation\nmy_decoded_str = my_str_as_bytes.decode()\ntype(my_decoded_str) # ensure it is string representation<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Q: The Best way to convert string to bytes in Python 3?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong> &nbsp;The first parameter to&nbsp;<a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.encode\"><code>encode<\/code><\/a>&nbsp;<em>defaults to<\/em>&nbsp;<code>'utf-8'<\/code>&nbsp;ever since Python 3.0. Thus the <em>absolutely<\/em> best way is:-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>b = mystring.encode()<\/code><\/pre>\n\n\n\n<p>This will also be faster because the default argument results not in the string&nbsp;<code>\"utf-8\"<\/code>&nbsp;in the C code, but&nbsp;<em><code>NULL<\/code><\/em>, which is&nbsp;<em>much<\/em>&nbsp;faster to check!<\/p>\n\n\n\n<p><strong>Source:<\/strong> https:\/\/stackoverflow.com\/questions\/7585435\/best-way-to-convert-string-to-bytes-in-python-3<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts and suggestions on this tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong>&nbsp;This example (Project) is developed in&nbsp;PyCharm 2018.2 (Community Edition)<br>JRE: 1.8.0<br>JVM:&nbsp;<a href=\"https:\/\/openjdk.java.net\/\">OpenJDK<\/a>&nbsp;64-Bit Server VM by JetBrains s.r.o<br>macOS 10.13.6<br><strong>Python&nbsp;3.7<\/strong><br>All<strong>&nbsp;Examples Convert  method used bytes() and encode() Python <\/strong>are in Python 3, so it may change its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>To convert string to bytes in Python, you have to use a bytes() method or encode()&nbsp;function. A bytes() method returns a bytes object which is immutable (value can&#8217;t be modified). If you want a mutable value then use&nbsp;bytearray()&nbsp;method. String to bytes is more popular these days due to the fact that for handling files or&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Convert string to bytes Python | bytes &#038; encode method<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[136,175],"post_series":[],"class_list":["post-7239","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-code","tag-python-convert"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Convert string to bytes Python | bytes &amp; encode method - EyeHunts<\/title>\n<meta name=\"description\" content=\"To convert string to bytes in Python, you have to use a bytes() method. A bytes() method returns a bytes object which is immutable.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert string to bytes Python | bytes &amp; encode method - EyeHunts\" \/>\n<meta property=\"og:description\" content=\"To convert string to bytes in Python, you have to use a bytes() method. A bytes() method returns a bytes object which is immutable.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-08T18:03:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-30T13:10:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/\",\"name\":\"Convert string to bytes Python | bytes & encode method - EyeHunts\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png\",\"datePublished\":\"2020-01-08T18:03:26+00:00\",\"dateModified\":\"2021-08-30T13:10:55+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"To convert string to bytes in Python, you have to use a bytes() method. A bytes() method returns a bytes object which is immutable.\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#primaryimage\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Convert string to bytes Python | bytes &#038; encode method\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert string to bytes Python | bytes & encode method - EyeHunts","description":"To convert string to bytes in Python, you have to use a bytes() method. A bytes() method returns a bytes object which is immutable.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/","og_locale":"en_US","og_type":"article","og_title":"Convert string to bytes Python | bytes & encode method - EyeHunts","og_description":"To convert string to bytes in Python, you have to use a bytes() method. A bytes() method returns a bytes object which is immutable.","og_url":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/","og_site_name":"Tutorial","article_published_time":"2020-01-08T18:03:26+00:00","article_modified_time":"2021-08-30T13:10:55+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/","url":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/","name":"Convert string to bytes Python | bytes & encode method - EyeHunts","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png","datePublished":"2020-01-08T18:03:26+00:00","dateModified":"2021-08-30T13:10:55+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"To convert string to bytes in Python, you have to use a bytes() method. A bytes() method returns a bytes object which is immutable.","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#primaryimage","url":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png","contentUrl":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/01\/convert-a-string-to-bytes-encode-300x161.png"},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-string-to-bytes-python-bytes-encode-method\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Convert string to bytes Python | bytes &#038; encode method"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":33648,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-xor-string\/","url_meta":{"origin":7239,"position":0},"title":"Python XOR string","author":"Rohit","date":"November 1, 2022","format":false,"excerpt":"If you want to Python XOR two strings, it means you want to XOR each character of one string with the character of the other string. You should then XOR ord() value of each char or str1 with ord() value of each char of str2. We have utilized the iterator\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python XOR string","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/11\/Python-XOR-string.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8142,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-string-length-len-function-and-other-ways\/","url_meta":{"origin":7239,"position":1},"title":"Python string length | len() function and Other ways","author":"Rohit","date":"April 21, 2020","format":false,"excerpt":"The best way to get Python string length is by using the len() function. len() function is an inbuilt function in the Python programming language. You can use other ways also to find the length of Given a string. Here are the ways to find\u00a0the length\u00a0of\u00a0a string\u00a0in\u00a0python\u00a0without using the len()\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/04\/Python-string-length-len-function-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/04\/Python-string-length-len-function-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/04\/Python-string-length-len-function-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/04\/Python-string-length-len-function-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":12976,"url":"https:\/\/tutorial.eyehunts.com\/js\/byte-array-to-base64-javascript-examples-code\/","url_meta":{"origin":7239,"position":2},"title":"Byte Array to Base64 JavaScript | Examples code","author":"Rohit","date":"May 8, 2021","format":false,"excerpt":"Use fromCharCode() and btoa() method to Byte array to base64 in JavaScript. The fromCharCode() method converts Unicode values into characters. It is a static method of the String object. The btoa() method encodes a string in base-64. Convert a bytes array to base64 String example A function\/program that converts an\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"Convert a bytes array to base64 String example","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/05\/Convert-a-bytes-array-to-base64-String-example.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":35681,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-json-dump-function\/","url_meta":{"origin":7239,"position":3},"title":"Python JSON dump function","author":"Rohit","date":"January 25, 2023","format":false,"excerpt":"Python JSON dump function converts the objects into appropriate JSON objects. It is used to\u00a0write Python serialized objects as JSON formatted data into a file. json.dump(object, skipkeys=False, ensure_ascii=True, indent=None, allow_nan=True, number_mode = None, datetime_mode = None, separators=None) obj is nothing but a Python serializable object which you want to convert\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-JSON-dump-function-example.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-JSON-dump-function-example.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-JSON-dump-function-example.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-JSON-dump-function-example.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":41514,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-write-bytes-to-file\/","url_meta":{"origin":7239,"position":4},"title":"Python write bytes to file","author":"Rohit","date":"August 4, 2023","format":false,"excerpt":"In Python, you can write bytes to a file using the built-in open() function in binary mode, and then use the write() method to write the bytes to the file. To write bytes to a file in Python, you need to follow these steps: Open the file in binary write\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/08\/Python-write-bytes-to-file.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/08\/Python-write-bytes-to-file.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/08\/Python-write-bytes-to-file.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/08\/Python-write-bytes-to-file.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/08\/Python-write-bytes-to-file.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":22376,"url":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-string-to-double-example-code\/","url_meta":{"origin":7239,"position":5},"title":"Convert Python string to double | Example code","author":"Rohit","date":"November 18, 2021","format":false,"excerpt":"Use the float() method or decimal() method to convert string to double in Python. The conversion of string to double is the same as the conversion of string to float. If the string contains non-numeric characters, then the float() function will raise a ValueError exception. Example convert a string to\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Convert Python string to double","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Convert-Python-string-to-double.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/7239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=7239"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/7239\/revisions"}],"predecessor-version":[{"id":18866,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/7239\/revisions\/18866"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=7239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=7239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=7239"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=7239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}