{"id":540,"date":"2024-11-20T03:47:26","date_gmt":"2024-11-20T03:47:26","guid":{"rendered":"https:\/\/techkubo.com\/python\/?p=540"},"modified":"2025-06-21T16:58:27","modified_gmt":"2025-06-21T16:58:27","slug":"python-for-loops","status":"publish","type":"post","link":"https:\/\/techkubo.com\/python\/python-for-loops\/","title":{"rendered":"Python For Loops"},"content":{"rendered":"\n<p>A <code>for<\/code> loop allows you to iterate over a sequence of elements, such as a list, tuple, string, or range. It is useful for performing repetitive tasks on each item in a sequence.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic For Loop<\/h2>\n\n\n\n<p>The basic syntax of a <code>for<\/code> loop is as follows:<\/p>\n\n\n\n<p>The <code>for<\/code> loop iterates over each item in the sequence, executing the indented block of code for each item.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">for item in sequence:\n    # Code to be executed<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In this example, the loop prints each fruit in the <code>fruits<\/code> list.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor fruit in fruits:\n    print(fruit)<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Looping Through a String<\/h2>\n\n\n\n<p>You can use a <code>for<\/code> loop to iterate over each character in a string. The loop iterates over each character in the string and executes the code block for each character.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">text = &quot;Hello&quot;\nfor char in text:\n    print(char)<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Looping Through a Range<\/h2>\n\n\n\n<p>The <code>range()<\/code> function creates a sequence of numbers from 0 up to (but not including) the specified end value, which can be used to control the number of times a loop executes. In this example, the loop prints numbers from 0 to 4.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">for i in range(5):\n    print(i)<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Looping with an Else Clause<\/h2>\n\n\n\n<p>You can include an <code>else<\/code> clause with a <code>for<\/code> loop. The <code>else<\/code> block will be executed after the loop finishes iterating over all items in the sequence. The <code>else<\/code> block runs after the loop completes normally.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">for i in range(5):\n    print(i)\nelse:\n    print(&quot;Loop is finished&quot;)<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Breaking out of a For Loop<\/h2>\n\n\n\n<p>You can use the <code>break<\/code> statement to exit a <code>for<\/code> loop prematurely, even if there are more items to iterate over.<\/p>\n\n\n\n<p>In this example, the loop prints numbers from 0 to 4 and then exits when <code>i<\/code> is equal to 5. The <code>break<\/code> statement immediately terminates the loop.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">for i in range(10):\n    if i == 5:\n        break\n    print(i)<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Skipping Iterations in a For Loop<\/h2>\n\n\n\n<p>The <code>continue<\/code> statement skips the current iteration and moves to the next iteration of the loop.<\/p>\n\n\n\n<p> In this example, the loop prints only odd numbers from 0 to 9. The <code>continue<\/code> statement allows you to skip specific iterations based on a condition.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">for i in range(10):\n    if i % 2 == 0:\n        continue\n    print(i)<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nested For Loops<\/h2>\n\n\n\n<p>You can nest <code>for<\/code> loops within each other to iterate over multi-dimensional data structures.<\/p>\n\n\n\n<p>This example prints each item in a 2D list (matrix) in a structured format. Nested <code>for<\/code> loops allow you to iterate over each item in a multi-dimensional sequence.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">matrix = [\n    [1, 2, 3],\n    [4, 5, 6],\n    [7, 8, 9]\n]\n\nfor row in matrix:\n    for item in row:\n        print(item, end=&quot; &quot;)\n    print()<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python For Loops Example Code<\/strong><\/h2>\n\n\n\n<p>This program uses <code>for<\/code> loops to iterate over lists, strings, ranges, and demonstrates breaking out of loops, skipping iterations, and nesting loops.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\"># Basic for loop\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor fruit in fruits:\n    print(fruit)\n\n# Looping through a string\ntext = &quot;Hello&quot;\nfor char in text:\n    print(char)\n\n# Looping through a range\nfor i in range(5):\n    print(i)\n\n# Looping with an else clause\nfor i in range(5):\n    print(i)\nelse:\n    print(&quot;Loop is finished&quot;)\n\n# Breaking out of a for loop\nfor i in range(10):\n    if i == 5:\n        break\n    print(i)\n\n# Skipping iterations in a for loop\nfor i in range(10):\n    if i % 2 == 0:\n        continue\n    print(i)\n\n# Nested for loops\nmatrix = [\n    [1, 2, 3],\n    [4, 5, 6],\n    [7, 8, 9]\n]\n\nfor row in matrix:\n    for item in row:\n        print(item, end=&quot; &quot;)\n    print()<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"550\" src=\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png\" alt=\"\" class=\"wp-image-542\" style=\"width:1200px;height:auto\" srcset=\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png 1024w, https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1-300x161.png 300w, https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1-768x413.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python Labs<\/strong><\/h2>\n\n\n\n<iframe src=\"https:\/\/techkubo.com\/python-sim.html\" title=\"Try Python on TechKubo\" width=\"100%\" height=\"500\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>A for loop allows you to iterate over a sequence of elements, such as a list, tuple, string, or range. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-540","post","type-post","status-publish","format-standard","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python For Loops - Python Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techkubo.com\/python\/python-for-loops\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python For Loops - Python Tutorial\" \/>\n<meta property=\"og:description\" content=\"A for loop allows you to iterate over a sequence of elements, such as a list, tuple, string, or range. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techkubo.com\/python\/python-for-loops\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-20T03:47:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-21T16:58:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Manong\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manong\" \/>\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\":\"Article\",\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/\"},\"author\":{\"name\":\"Manong\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\"},\"headline\":\"Python For Loops\",\"datePublished\":\"2024-11-20T03:47:26+00:00\",\"dateModified\":\"2025-06-21T16:58:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/\"},\"wordCount\":352,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/python\/#organization\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png\",\"articleSection\":[\"python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/techkubo.com\/python\/python-for-loops\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/\",\"url\":\"https:\/\/techkubo.com\/python\/python-for-loops\/\",\"name\":\"Python For Loops - Python Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/python\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png\",\"datePublished\":\"2024-11-20T03:47:26+00:00\",\"dateModified\":\"2025-06-21T16:58:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/techkubo.com\/python\/python-for-loops\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage\",\"url\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png\",\"contentUrl\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png\",\"width\":1024,\"height\":550},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/techkubo.com\/python\/python-for-loops\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/techkubo.com\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python For Loops\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/techkubo.com\/python\/#website\",\"url\":\"https:\/\/techkubo.com\/python\/\",\"name\":\"Python Tutorial\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/techkubo.com\/python\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/techkubo.com\/python\/#organization\",\"name\":\"Python Tutorial\",\"url\":\"https:\/\/techkubo.com\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png\",\"contentUrl\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png\",\"width\":1620,\"height\":1156,\"caption\":\"Python Tutorial\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\",\"name\":\"Manong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"caption\":\"Manong\"},\"sameAs\":[\"https:\/\/techkubo.com\"],\"url\":\"https:\/\/techkubo.com\/python\/author\/manong\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python For Loops - Python Tutorial","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:\/\/techkubo.com\/python\/python-for-loops\/","og_locale":"en_US","og_type":"article","og_title":"Python For Loops - Python Tutorial","og_description":"A for loop allows you to iterate over a sequence of elements, such as a list, tuple, string, or range. [&hellip;]","og_url":"https:\/\/techkubo.com\/python\/python-for-loops\/","og_site_name":"Python Tutorial","article_published_time":"2024-11-20T03:47:26+00:00","article_modified_time":"2025-06-21T16:58:27+00:00","og_image":[{"width":1024,"height":550,"url":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png","type":"image\/png"}],"author":"Manong","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manong","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#article","isPartOf":{"@id":"https:\/\/techkubo.com\/python\/python-for-loops\/"},"author":{"name":"Manong","@id":"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965"},"headline":"Python For Loops","datePublished":"2024-11-20T03:47:26+00:00","dateModified":"2025-06-21T16:58:27+00:00","mainEntityOfPage":{"@id":"https:\/\/techkubo.com\/python\/python-for-loops\/"},"wordCount":352,"commentCount":0,"publisher":{"@id":"https:\/\/techkubo.com\/python\/#organization"},"image":{"@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage"},"thumbnailUrl":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png","articleSection":["python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techkubo.com\/python\/python-for-loops\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techkubo.com\/python\/python-for-loops\/","url":"https:\/\/techkubo.com\/python\/python-for-loops\/","name":"Python For Loops - Python Tutorial","isPartOf":{"@id":"https:\/\/techkubo.com\/python\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage"},"image":{"@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage"},"thumbnailUrl":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png","datePublished":"2024-11-20T03:47:26+00:00","dateModified":"2025-06-21T16:58:27+00:00","breadcrumb":{"@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techkubo.com\/python\/python-for-loops\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#primaryimage","url":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png","contentUrl":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2024\/11\/py-ForLoops-Image1.png","width":1024,"height":550},{"@type":"BreadcrumbList","@id":"https:\/\/techkubo.com\/python\/python-for-loops\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techkubo.com\/python\/"},{"@type":"ListItem","position":2,"name":"Python For Loops"}]},{"@type":"WebSite","@id":"https:\/\/techkubo.com\/python\/#website","url":"https:\/\/techkubo.com\/python\/","name":"Python Tutorial","description":"","publisher":{"@id":"https:\/\/techkubo.com\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techkubo.com\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techkubo.com\/python\/#organization","name":"Python Tutorial","url":"https:\/\/techkubo.com\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/","url":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png","contentUrl":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png","width":1620,"height":1156,"caption":"Python Tutorial"},"image":{"@id":"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965","name":"Manong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/python\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","caption":"Manong"},"sameAs":["https:\/\/techkubo.com"],"url":"https:\/\/techkubo.com\/python\/author\/manong\/"}]}},"_links":{"self":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts\/540"}],"collection":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/comments?post=540"}],"version-history":[{"count":3,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":751,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts\/540\/revisions\/751"}],"wp:attachment":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/media?parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/categories?post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/tags?post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}