{"id":37306,"date":"2016-08-30T21:33:29","date_gmt":"2016-08-31T02:33:29","guid":{"rendered":"http:\/\/luispalominotblog.wordpress.com\/?p=585"},"modified":"2016-08-30T21:33:29","modified_gmt":"2016-08-31T02:33:29","slug":"no-strings-attached","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/no-strings-attached\/","title":{"rendered":"No strings attached"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/luispalominotblog.wordpress.com\/2016\/08\/31\/no-strings-attached\/\"><a href=\"https:\/\/luispalominotblog.wordpress.com\">Programming<\/a><\/a><\/em><br \/><\/p>\n<h1>Creation and use of Strings<\/h1>\n<p>Today, we are going to be talking about a very simple topic, how to create and use strings in Python. You may think that you&#8217;ve already mastered the art of strings, but you would be surprised if you knew that you don&#8217;t know the full potential of strings. Let&#8217;s begin.<\/p>\n<p>A string is one of the most popular data types in Python, they can be created by surrounding a sentence in double quotes &#8220;&#8221; or single quotes &#8221;. You use them when you print them out to the console and when you assign a string to a variable.<\/p>\n<h2>Access substrings\u00a0in Strings<\/h2>\n<p>Unlike other languages, Python does not support the character type, so any value that is contained within a string is going to be called substrings. To access is pretty simple, since it is the same as if we had a list and we wanted to get the value at i position.\u00a0<img class=\" size-full wp-image-615 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/115.png?w=775\" alt=\"1.png\"   \/><\/p>\n<h2>Slicing Strings<\/h2>\n<p>Just like with lists, we can slice a string by using the square brackets along with the indices to obtain the new string.<\/p>\n<p><img class=\" size-full wp-image-620 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/214.png?w=775\" alt=\"2.png\"   \/><\/p>\n<p><img class=\" size-full wp-image-622 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/311.png?w=775\" alt=\"3.png\"   \/><\/p>\n<h2>Non Printable Characters<\/h2>\n<p>If\u00a0you use a non printable character inside a string, they are not going to be printed. These non printable characters, also called escape characters, are not going to be printed by the console, instead they are going to make some changes to you string. Don&#8217;t worry if you don&#8217;w understand yet, let me use some examples.<\/p>\n<p><img class=\" size-full wp-image-629 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/411.png?w=775\" alt=\"4.png\"   \/><\/p>\n<p><img class=\" size-full wp-image-631 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/54.png?w=775\" alt=\"5.png\"   \/><\/p>\n<h2>Special Operators<\/h2>\n<p>Here is a list with examples of the most important string operators that you are eventually going to be using.<\/p>\n<p><img class=\" size-full wp-image-635 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/61.png?w=775\" alt=\"6.png\"   \/><\/p>\n<p><img class=\" size-full wp-image-637 aligncenter\" src=\"https:\/\/luispalominotblog.files.wordpress.com\/2016\/08\/7.png?w=775\" alt=\"7.png\"   \/><\/p>\n<h2>Built-in String Methods (Functions)<\/h2>\n<p>As you should remember, lists have their methods to manipulate and insert data. Some examples for those methods are the<em> append()<\/em> or the <em>insert()<\/em>. But fortunately strings have also their own set <div class=\"post-limited-image\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/luispalominotblog.wordpress.com\/585\/\" \/><\/div>\n<div class=\"post-limited-image\"><img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=luispalominotblog.wordpress.com&#038;blog=115253528&%23038;post=585&%23038;subd=luispalominotblog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div><!--more--> methods that can be used whenever you want. We are going to list some of the most important ones explaining their functionality.<\/p>\n<ul>\n<li>count (substring, begin, end): Counts and returns how many times the substring given was found in the String\u00a0within the range given<\/li>\n<li>endswith (suffix, begin, end): Returns true if a string ends with the suffix given<\/li>\n<li>find (substring, begin, end): Determines if the substring is within the string and, if found, it returns its position. The method will return the first substring it finds, if not fount, it will return -1.<\/li>\n<li>isdigit(): Returns true if the string contains only digits<\/li>\n<li>len(string) returns the length of the string<\/li>\n<\/ul>\n<h3><\/h3><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/luispalominotblog.wordpress.com\/585\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/luispalominotblog.wordpress.com\/585\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=luispalominotblog.wordpress.com&#038;blog=115253528&%23038;post=585&%23038;subd=luispalominotblog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Programming Creation and use of Strings Today, we are going to be talking about a very simple topic, how to create and use strings in Python. You may think that you&#8217;ve already mastered the art of strings, but you would be surprised if you knew that you don&#8217;t know the full potential &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/no-strings-attached\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">No strings attached<\/span><\/a><\/p>\n","protected":false},"author":14,"featured_media":615,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[24,160,33],"class_list":["post-37306","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-python","tag-strings","tag-tc101"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/37306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=37306"}],"version-history":[{"count":15,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/37306\/revisions"}],"predecessor-version":[{"id":42900,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/37306\/revisions\/42900"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=37306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=37306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=37306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}