{"id":103,"date":"2019-02-01T01:43:02","date_gmt":"2019-02-01T01:43:02","guid":{"rendered":"https:\/\/kindsonthegenius.com\/python\/?p=103"},"modified":"2026-07-04T01:20:59","modified_gmt":"2026-07-04T01:20:59","slug":"09-python-strings","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/python\/09-python-strings\/","title":{"rendered":"Python &#8211; Strings"},"content":{"rendered":"<p>We would cover strings under the following topics:<\/p>\n<ol>\n<li><a href=\"#t1\">Introduction<\/a><\/li>\n<li><a href=\"#t2\">Accessing String Values<\/a><\/li>\n<li><a href=\"#t3\">Escape Characters<\/a><\/li>\n<li><a href=\"#t4\">Special String Operators<\/a><\/li>\n<li><a href=\"#t5\">Formatting a String<\/a><\/li>\n<li><a href=\"#t6\">Multi-line Strings<\/a><\/li>\n<li><a href=\"#t7\">Unicode Characters<\/a><\/li>\n<li><a href=\"#t8\">String Methods<\/a><\/li>\n<li><a href=\"#t9\">Watch the Video<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Introduction<\/strong><\/h4>\n<p>A string in Python is a sequence characters enclosed in quotes. However, both single and double quotes are treated the same in Python.<\/p>\n<p>As you know, you don&#8217;t have to declare a string variable before using it. You simply need to assign a string to a variable. For example, the following statements creates strings:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">channel <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Python Programming Tutorials\"<\/span>\r\nname <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Kindson The Genius\"<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Accessing String Values<\/strong><\/h4>\n<p>It is important to note that Python does not have character type. It treats characters just the same a strings. So a single character is considered to be a string of length 1.<\/p>\n<p>You can access string and also part of a string using the index.\u00a0 The index begins from 0 (the first character in the string) to the length of the string.<\/p>\n<p>Let&#8217;s take for example:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">channel <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Python Programming Tutorials\"<\/span>\r\nname <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Kindson The Genius\"<\/span>\r\n\r\nstr1 <span style=\"color: #333333;\">=<\/span> channel[<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>]\r\nfirstname <span style=\"color: #333333;\">=<\/span> name[<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>:<span style=\"color: #0000dd; font-weight: bold;\">7<\/span>]\r\n\r\n<span style=\"color: #007020;\">print<\/span>(str1)\r\n<span style=\"color: #007020;\">print<\/span>(firstname)<span style=\"background-color: #fff0f0;\">\"<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>If the above program executes, then the variable str1 would contain the letter P. Also, the variable firstname would contain the string Kindson.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">\u00a03.Escape Characters<\/strong><\/h4>\n<p>Escape characters are characters used for formatting a string output. They are also called non-printable characters. Escape characters are represented using backslash notation.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Notation<\/th>\n<th>Hex character<\/th>\n<th class=\"ts\">What it means<\/th>\n<\/tr>\n<tr>\n<td>\\a<\/td>\n<td>0x07<\/td>\n<td>Bell or alert<\/td>\n<\/tr>\n<tr>\n<td>\\b<\/td>\n<td>0x08<\/td>\n<td>Backspace<\/td>\n<\/tr>\n<tr>\n<td>\\cx<\/td>\n<td><\/td>\n<td>Control-x<\/td>\n<\/tr>\n<tr>\n<td>\\C-x<\/td>\n<td><\/td>\n<td>Control-x<\/td>\n<\/tr>\n<tr>\n<td>\\e<\/td>\n<td>0x1b<\/td>\n<td>Escape<\/td>\n<\/tr>\n<tr>\n<td>\\f<\/td>\n<td>0x0c<\/td>\n<td>Formfeed<\/td>\n<\/tr>\n<tr>\n<td>\\M-\\C-x<\/td>\n<td><\/td>\n<td>Meta-Control-x<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>0x0a<\/td>\n<td>Newline character<\/td>\n<\/tr>\n<tr>\n<td>\\nnn<\/td>\n<td><\/td>\n<td>Octal notation, where n is in the range 0.7<\/td>\n<\/tr>\n<tr>\n<td>\\r<\/td>\n<td>0x0d<\/td>\n<td>Carriage return<\/td>\n<\/tr>\n<tr>\n<td>\\s<\/td>\n<td>0x20<\/td>\n<td>Space<\/td>\n<\/tr>\n<tr>\n<td>\\t<\/td>\n<td>0x09<\/td>\n<td>Tab<\/td>\n<\/tr>\n<tr>\n<td>\\v<\/td>\n<td>0x0b<\/td>\n<td>Vertical tab<\/td>\n<\/tr>\n<tr>\n<td>\\x<\/td>\n<td><\/td>\n<td>Character x<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">\\xnn<\/td>\n<td><\/td>\n<td>Hexadecimal notation. n is in the range from 0.9, a.f, or A.F<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Special String Operators<\/strong><\/h4>\n<p>There are some operators that can be used to perform certain operations in a string. For example, joining two strings together or splitting a string into parts. Or maybe retrieving part of a string. The table below gives a list of these operators and their description.<\/p>\n<p>Assuming a = &#8220;Hello&#8221; and b = &#8220;Python&#8221;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Operator<\/th>\n<th>Operation description<\/th>\n<th>For example<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">+<\/td>\n<td>Concatenation &#8211; Adds two strings togeterh<\/td>\n<td class=\"ts\">a + b will give HelloPython<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">*<\/td>\n<td>Repetition &#8211; Creates new strings, by joining multiple copies of the same string<\/td>\n<td class=\"ts\">a*2 will give -HelloHello<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">[]<\/td>\n<td>Slice &#8211; Produces the character from the specified index<\/td>\n<td class=\"ts\">a[1] will give e<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">[ : ]<\/td>\n<td>Range Slice &#8211; Gives the characters from the specified range<\/td>\n<td class=\"ts\">a[1:4] will give ell<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">in<\/td>\n<td>Membership &#8211; Returns true if a character exists in the specified string<\/td>\n<td class=\"ts\">H in a will give 1<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">not in<\/td>\n<td>Membership &#8211; Returns true if a character does not exist in the specified string<\/td>\n<td class=\"ts\">M not in a will give 1<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">r\/R<\/td>\n<td>Raw String &#8211; Suppresses actual meaning of the Escape characters. The syntax for raw strings is exactly the same as for normal strings with the exception of the raw string operator, the letter &#8220;r,&#8221; which precedes the quotation marks. The &#8220;r&#8221; can be lowercase (r) or uppercase (R) and must be placed immediately before the opening quotation mark.<\/td>\n<td class=\"ts\">print r&#8217;\\n&#8217; prints \\n and print R&#8217;\\n&#8217;prints \\n<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%<\/td>\n<td>Format &#8211; Performs formatting on a string<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Formatting a String<\/strong><\/h4>\n<p>A string can be formatted using the formatting operator, %. It kind of allows you to get the behavior of the printf() function used in C programming language.<\/p>\n<p>To use it, you place the formatter inside a string and then specify the string that should be in place of the formatter. For example:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"My first car was %s. I used if for %d years\"<\/span> <span style=\"color: #333333;\">%<\/span>(<span style=\"background-color: #fff0f0;\">\"Camry\"<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>If the above line executes, then the output will be:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">My first car <span style=\"color: #000000; font-weight: bold;\">is<\/span> Camry<span style=\"color: #333333;\">.<\/span> I used <span style=\"color: #008800; font-weight: bold;\">if<\/span> <span style=\"color: #008800; font-weight: bold;\">for<\/span> <span style=\"color: #0000dd; font-weight: bold;\">6<\/span> years\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The complete list of string formatters are given in the table below:<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Formatter<\/th>\n<th>Converts to<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">%c<\/td>\n<td>character<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%s<\/td>\n<td>string conversion via str() prior to formatting<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%i<\/td>\n<td>signed decimal integer<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%d<\/td>\n<td>signed decimal integer<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%u<\/td>\n<td>unsigned decimal integer<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%o<\/td>\n<td>octal integer<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%x<\/td>\n<td>hexadecimal integer (lowercase letters)<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%X<\/td>\n<td>hexadecimal integer (UPPERcase letters)<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%e<\/td>\n<td>exponential notation (with lowercase &#8216;e&#8217;)<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%E<\/td>\n<td>exponential notation (with UPPERcase &#8216;E&#8217;)<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%f<\/td>\n<td>floating point real number<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%g<\/td>\n<td>the shorter of %f and %e<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%G<\/td>\n<td>the shorter of %f and %E<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Other symbols that could also be used are given below. I recommend you try each of them to see how they work.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Symbol<\/th>\n<th>What is does<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">*<\/td>\n<td>argument specifies width or precision.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">&#8211;<\/td>\n<td>left justification.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">+<\/td>\n<td>display the sign.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">&lt;sp&gt;<\/td>\n<td>leaves a blank space before a positive number.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">#<\/td>\n<td>adds the octal leading zero ( &#8216;0&#8217; ) or hexadecimal leading &#8216;0x&#8217; or &#8216;0X&#8217;, depending on whether &#8216;x&#8217; or &#8216;X&#8217; were used.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">0<\/td>\n<td>pad from left with zeros<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">%<\/td>\n<td>&#8216;%%&#8217; leaves you with a single string literal &#8216;%&#8217;<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">(var)<\/td>\n<td>mapping variable (dictionary arguments)<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">m.n.<\/td>\n<td>m is the minimum total width and n is the number of digits to display after the decimal point<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h4><b id=\"t6\">6. Multi-line<\/b><strong>\u00a0Strings<\/strong><\/h4>\n<p>Python also supports multi-line strings. This achieved using triple quotation marks. For example:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">text <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"It is very good for you to learn programming. <\/span>\r\n<span style=\"background-color: #fff0f0;\">I also think that starting with Python is probably the<\/span>\r\n<span style=\"background-color: #fff0f0;\">easiest way to achieve it. The remember to watch the <\/span>\r\n<span style=\"background-color: #fff0f0;\">videos\"\"\"<\/span>\r\n<\/pre>\n<p>Also, you can place escape characters inside the multiline string. For example, you may want to force a new line, in that case you simple add \\n inside the string. Try to watch the video to see how all these works.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. Unicode String<\/strong><\/h4>\n<p>A normal Python string is stored in memory as 8-bit ASCII code. While unicode strings are stored as 16-bit unicode. The benefit of this is to allow a wider range of character set. For example some foreign language characters or scripts. (eg Chinese!)<\/p>\n<p>to create a unicode string, simply place letter u before the string. This is shown below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">ustr <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">u'Python Programing'<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t8\">8. String Method<\/strong><\/h4>\n<p>It&#8217;s important for you to know how to manipulate strings. This you can do using the string methods. A table of string methods and description is given below.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SN<\/th>\n<th>Methods and brief description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>capitalize()<\/strong>Capitalizes first letter of particular string<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>center(width, fillchar)<\/strong>Returns a space-padded string with the original string centered to a total of width columns.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>count(str, beg= 0,end=len(string))<\/strong>Counts how many times str occurs in string or in a substring of string if starting index beg and ending index end are given.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><strong>decode(encoding=&#8217;UTF-8&#8242;,errors=&#8217;strict&#8217;)<\/strong>Decodes the string using the codec registered for encoding. encoding defaults to the default string encoding.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><strong>encode(encoding=&#8217;UTF-8&#8242;,errors=&#8217;strict&#8217;)<\/strong>Returns encoded string version of string; on error, default is to raise a ValueError unless errors is given with &#8216;ignore&#8217; or &#8216;replace&#8217;.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><strong>endswith(suffix, beg=0, end=len(string))<\/strong>Checks if string or a substring of string (if starting index beg and ending index end are given) ends with suffix; returns true if yes. Returns false if otherwise<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><strong>expandtabs(tabsize=8)<\/strong>Expands tabs in string to multiple spaces; defaults to 8 spaces per tab if tabsize not provided.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><strong>find(str, beg=0 end=len(string))<\/strong>Determine if str occurs in string or in a substring of string if starting index beg and ending index end are given returns index if found and -1 otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">9<\/td>\n<td><strong>index(str, beg=0, end=len(string))<\/strong>Same as find(), but raises an exception if str not found.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">10<\/td>\n<td><strong>isalnum()<\/strong>Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">11<\/td>\n<td><strong>isalpha()<\/strong>Returns true if string has at least 1 character and all characters are alphabetic and false otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">12<\/td>\n<td><strong>isdigit()<\/strong>Returns true if string contains only digits and false otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">13<\/td>\n<td><strong>islower()<\/strong>Returns true if string has at least 1 cased character and all cased characters are in lowercase and false otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">14<\/td>\n<td><strong>isnumeric()<\/strong>Returns true if a unicode string contains only numeric characters. It returns false if otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">15<\/td>\n<td><strong>isspace()<\/strong>Returns true if string contains only whitespace characters. It returns false if otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">16<\/td>\n<td><strong>istitle()<\/strong>Returns true if string is properly &#8220;titlecased&#8221; and false otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">17<\/td>\n<td><strong>isupper()<\/strong>Returns true if string has at least one cased character and all cased characters are in uppercase. It returns if otherwise.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">18<\/td>\n<td><strong>join(seq)<\/strong>Merges the string representations of elements in sequence seq into a string, with separator string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">19<\/td>\n<td><strong>len(string)<\/strong>Returns the length of the string. That is number of characters in the string<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">20<\/td>\n<td><strong>ljust(width[, fillchar])<\/strong>Returns a space-padded string with the original string left-justified to a total of width columns.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">21<\/td>\n<td><strong>lower()<\/strong>Converts all uppercase letters in string to lowercase.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">22<\/td>\n<td><strong>lstrip()<\/strong>Removes all leading whitespace in string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">23<\/td>\n<td><strong>maketrans()<\/strong>Returns a translation table to be used in translate function.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">24<\/td>\n<td><strong>max(str)<\/strong>Returns the max alphabetical character from the string str.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">25<\/td>\n<td><strong>min(str)<\/strong>Returns the min alphabetical character from the string str.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">26<\/td>\n<td><strong>replace(old, new [, max])<\/strong>Replaces all occurrences of old in string with new or at most max occurrences if max given.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">27<\/td>\n<td><strong>rfind(str, beg=0,end=len(string))<\/strong>Same as find(), but search backwards in string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">28<\/td>\n<td><strong>rindex( str, beg=0, end=len(string))<\/strong>Same as index(), but searched backwards in the given string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">29<\/td>\n<td><strong>rjust(width,[, fillchar])<\/strong>Returns a space-padded string with the original string right-justified to a total of width columns.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">30<\/td>\n<td><strong>rstrip()<\/strong>Removes all trailing whitespace of string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">31<\/td>\n<td><strong>split(str=&#8221;&#8221;, num=string.count(str))<\/strong>Splits the string according to delimiter str (space if not provided) and returns list of substrings; split into at most num substrings if specified.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">32<\/td>\n<td><strong>splitlines( num=string.count(&#8216;\\n&#8217;))<\/strong>Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">33<\/td>\n<td><strong>startswith(str, beg=0,end=len(string))<\/strong>Checks if string or a substring of string (if starting index beg and ending index end are given) starts with substring str. Returns true if yes. Returns false if otherwise<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">34<\/td>\n<td><strong>strip([chars])<\/strong>Performs both lstrip() and rstrip() on string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">35<\/td>\n<td><strong>swapcase()<\/strong>Coverts uppercase letters to lowercase and lowercase letters to uppercase in a string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">36<\/td>\n<td><strong>title<\/strong>()Returns the\u00a0 &#8220;titlecased&#8221; version of string. This means that all words begin with uppercase and the rest are lowercase.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">37<\/td>\n<td><strong>translate(table, deletechars=&#8221;&#8221;)<\/strong>Translates string according to translation table str(256 chars), removing those in the del string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">38<\/td>\n<td><strong>upper()<\/strong>Converts the lowercase letters in string to uppercase.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">39<\/td>\n<td><strong>zfill (width)<\/strong>Returns the original string leftpadded with 0s to a total of width characters; intended for numbers. zfill() retains any sign given .<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">40<\/td>\n<td><strong>isdecimal()<\/strong>Returns true if a unicode string contains only decimal characters. Returns false if othewise.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t9\">9. Watch the video<\/strong><br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/4s7q9AuYU0c\" width=\"100%\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/h4>\n<p><!-- ktg-lesson-nav --><\/p>\n<nav class=\"ktg-lesson-nav\" aria-label=\"Lesson navigation\">\n<p><strong>Previous:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/python\/08-python-basic-math-and-numbers\/\">Lesson 8: Python &#8211; Basic Math &#038; Numbers<\/a><\/p>\n<p><strong>Next:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/python\/10-python-lists\/\">Lesson 10: Python &#8211; Lists<\/a><\/p>\n<\/nav>\n<p><!-- ktg-alkademy-cta --><\/p>\n<div class=\"ktg-alkademy-cta\" style=\"margin:2em 0;padding:1.25em;border-left:4px solid #2563eb;background:#f8fafc;\">\n<p><strong>Want live Python classes?<\/strong> Join <a href=\"https:\/\/www.alkademy.com\/courses\" target=\"_blank\" rel=\"noopener noreferrer\">Alkademy<\/a> for instructor-led Python and data science courses with hands-on projects.<\/p>\n<\/div>\n<p><!-- ktg-author-trust --><\/p>\n<div class=\"ktg-author-trust\" style=\"margin:2em 0;padding:1.25em;border-top:1px solid #e2e8f0;\">\n<p>Kindson Munonye is a software engineer and technical author specializing in Python, data science, and machine learning. He publishes free step-by-step Python tutorials and live classes on Alkademy.<\/p>\n<p><a href=\"https:\/\/github.com\/KindsonTheGenius\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a> \u00b7 <a href=\"https:\/\/www.linkedin.com\/in\/kindson\" target=\"_blank\" rel=\"noopener noreferrer\">LinkedIn<\/a> \u00b7 <a href=\"https:\/\/www.kindsonthegenius.com\/about\/\">About<\/a> \u00b7 <a href=\"https:\/\/www.alkademy.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Alkademy<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We would cover strings under the following topics: Introduction Accessing String Values Escape Characters Special String Operators Formatting a String Multi-line Strings Unicode Characters String &hellip; <\/p>\n","protected":false},"author":395,"featured_media":162,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[5],"tags":[7],"class_list":["post-103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials","tag-python-strings"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":6,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":575,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/103\/revisions\/575"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/media\/162"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/python\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}