{"id":46,"date":"2026-02-28T13:24:33","date_gmt":"2026-02-28T08:24:33","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=46"},"modified":"2026-03-12T11:35:30","modified_gmt":"2026-03-12T06:35:30","slug":"strings","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/strings\/","title":{"rendered":"Strings"},"content":{"rendered":"\n<p>Strings are one of the most commonly used data types in Python. A string is used to store text data such as names, messages, addresses, or any sequence of characters. In simple words, anything written inside quotation marks in Python is considered a string.<\/p>\n\n\n\n<p>Strings are widely used in real world applications such as user input, data processing, reporting systems, and web development.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CREATING STRINGS<\/strong><\/h1>\n\n\n\n<p>In Python, strings are created by enclosing text inside single quotes or double quotes.<\/p>\n\n\n\n<p>Examples:<\/p>\n\n\n\n<p>name = &#8220;Hira&#8221;<br>city = &#8216;Karachi&#8217;<br>message = &#8220;Welcome to Python&#8221;<\/p>\n\n\n\n<p>Both single and double quotes work the same way.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>MULTILINE STRINGS<\/strong><\/h1>\n\n\n\n<p>If you want to write text on multiple lines, you can use triple quotes.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>text = &#8220;&#8221;&#8221;Python is easy to learn<br>It is powerful and flexible<br>It is widely used worldwide&#8221;&#8221;&#8221;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>ACCESSING CHARACTERS IN A STRING<\/strong><\/h1>\n\n\n\n<p>Each character in a string has a position called an index. Indexing starts from 0.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>word = &#8220;Python&#8221;<br>print(word[0])<\/p>\n\n\n\n<p>Output will be P.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>STRING CONCATENATION<\/strong><\/h1>\n\n\n\n<p>You can join two or more strings using the plus operator.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>first_name = &#8220;Hira&#8221;<br>last_name = &#8220;Khan&#8221;<br>full_name = first_name + &#8221; &#8221; + last_name<\/p>\n\n\n\n<p>This combines both strings into one.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>STRING METHODS<\/strong><\/h1>\n\n\n\n<p>Python provides many built in functions to work with strings.<\/p>\n\n\n\n<p>upper() converts text to uppercase<br>lower() converts text to lowercase<br>strip() removes extra spaces<br>replace() replaces part of a string<br>len() counts the number of characters<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>text = &#8220;python&#8221;<br>print(text.upper())<\/p>\n\n\n\n<p>Output will be PYTHON.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CHECKING STRING TYPE<\/strong><\/h1>\n\n\n\n<p>You can check the type of a string using the type() function.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>name = &#8220;Ali&#8221;<br>print(type(name))<\/p>\n\n\n\n<p>This will show that the variable is of type string.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHY STRINGS ARE IMPORTANT<\/strong><\/h1>\n\n\n\n<p>Strings are essential for handling text based information in programs. They are used in printing messages, taking user input, storing data, and building applications.<\/p>\n\n\n\n<p>Understanding strings and their operations helps you manage text efficiently and build more interactive Python programs.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FUNDAMENTALS (PYF) > Variables and Data Types > Strings<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773297370761\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":8,"template":"","class_list":["post-46","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Strings - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python strings: create, access, concatenate, and manipulate text using built-in methods for interactive Python programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/strings\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Strings - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python strings: create, access, concatenate, and manipulate text using built-in methods for interactive Python programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/strings\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-12T06:35:30+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/strings\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/strings\\\/\",\"name\":\"Strings - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-02-28T08:24:33+00:00\",\"dateModified\":\"2026-03-12T06:35:30+00:00\",\"description\":\"Learn Python strings: create, access, concatenate, and manipulate text using built-in methods for interactive Python programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/strings\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/strings\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/strings\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FUNDAMENTALS (PYF) > Variables and Data Types > Strings\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Strings - One Language. Endless Possibilities","description":"Learn Python strings: create, access, concatenate, and manipulate text using built-in methods for interactive Python programs.","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:\/\/gigz.pk\/python\/lesson\/strings\/","og_locale":"en_US","og_type":"article","og_title":"Strings - One Language. Endless Possibilities","og_description":"Learn Python strings: create, access, concatenate, and manipulate text using built-in methods for interactive Python programs.","og_url":"https:\/\/gigz.pk\/python\/lesson\/strings\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-12T06:35:30+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/strings\/","url":"https:\/\/gigz.pk\/python\/lesson\/strings\/","name":"Strings - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-02-28T08:24:33+00:00","dateModified":"2026-03-12T06:35:30+00:00","description":"Learn Python strings: create, access, concatenate, and manipulate text using built-in methods for interactive Python programs.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/strings\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/strings\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/strings\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FUNDAMENTALS (PYF) > Variables and Data Types > Strings"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}