{"id":3582,"date":"2026-10-07T14:27:03","date_gmt":"2026-10-07T14:27:03","guid":{"rendered":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/"},"modified":"2026-10-07T14:27:12","modified_gmt":"2026-10-07T14:27:12","slug":"python-for-loop","status":"publish","type":"post","link":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/","title":{"rendered":"Python for Loop: Syntax and Examples for Server Scripts"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> a Python <code>for<\/code> loop runs the same block of code once for each item in a sequence: a list, a string, a dictionary, the lines of a file or a <code>range()<\/code> of numbers. The syntax is <code>for item in sequence:<\/code> followed by an indented block. Use <code>range()<\/code> to repeat something a set number of times, <code>enumerate()<\/code> when you also need a counter, <code>zip()<\/code> to walk two lists side by side, <code>break<\/code> to stop early and <code>continue<\/code> to skip an item. Every example below was run on Python 3.14.7, and the output shown is what we got.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"627\" src=\"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop-screenshot-1024x627.png\" alt=\"Terminal running the Python for loop examples on Python 3.14.8\" class=\"wp-image-3584\" srcset=\"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop-screenshot-1024x627.png 1024w, https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop-screenshot-300x184.png 300w, https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop-screenshot-768x471.png 768w, https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop-screenshot.png 1100w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">The first loops from this post running on Python 3.14.8.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The basic for loop<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>servers = [\"web1\", \"web2\", \"db1\"]\nfor server in servers:\n    print(\"Checking\", server)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Checking web1\nChecking web2\nChecking db1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The name after <code>for<\/code> (here <code>server<\/code>) takes the value of each item in turn. The colon and the indentation matter: everything indented under the <code>for<\/code> line is the loop body. Python has no <code>for (i = 0; i &lt; n; i++)<\/code> counter loop like C or Bash; you loop over things directly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Counting with range()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>range()<\/code> produces numbers on demand. As the <a href=\"https:\/\/docs.python.org\/3\/tutorial\/controlflow.html\" target=\"_blank\" rel=\"noopener noreferrer\">Python tutorial<\/a> points out, the end point is never included: <code>range(10)<\/code> gives 0 to 9.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i in range(1, 6):\n    print(i, end=\" \")\nprint()\nprint(list(range(0, 10, 3)))<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 2 3 4 5\n[0, 3, 6, 9]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The three arguments are start, stop (not included) and step. A negative step counts down: <code>range(10, 0, -1)<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">enumerate(), dictionaries and zip()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you need the position as well as the item, use <code>enumerate()<\/code> instead of <code>range(len(...))<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for number, server in enumerate(servers, start=1):\n    print(number, server)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 web1\n2 web2\n3 db1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Looping over a dictionary gives you its keys. Use <code>.items()<\/code> to get each key and value together:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>disk_used = {\"\/\": 71, \"\/var\": 93, \"\/home\": 45}\nfor mount, percent in disk_used.items():\n    if percent &gt; 90:\n        print(f\"WARNING: {mount} is {percent}% full\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>WARNING: \/var is 93% full<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>zip()<\/code> pairs up items from two or more lists, which is handy for building a hosts file or a report:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>names = [\"web1\", \"web2\", \"db1\"]\nips = [\"203.0.113.10\", \"203.0.113.11\", \"203.0.113.20\"]\nfor name, ip in zip(names, ips):\n    print(f\"{ip}\\t{name}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Be careful when the lists are not the same length: plain <code>zip()<\/code> silently stops at the shorter one, so a missing IP address simply drops a server from the output. Add <code>strict=True<\/code> and Python raises an error instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ValueError: zip() argument 2 is shorter than argument 1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">break, continue and the loop else<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>break<\/code> leaves the loop at once. <code>continue<\/code> skips the rest of the body for the current item and moves to the next. A <code>for<\/code> loop can also have an <code>else<\/code> block, which the Python tutorial describes precisely: it runs when the loop finishes without hitting <code>break<\/code>. That makes &#8220;search, and say so if nothing was found&#8221; very clean:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>free_gb = {\"web1\": 3, \"web2\": 42, \"db1\": 120}\nfor server, free in free_gb.items():\n    if free &gt;= 40:\n        print(\"Deploy to\", server)\n        break\nelse:\n    print(\"No server has enough space\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This prints <code>Deploy to web2<\/code>. Change the threshold to 500 and nothing matches, so the <code>else<\/code> block prints <code>No server has enough space<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>continue<\/code> is the natural way to skip blank lines and comments when reading a config file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"app.conf\") as config:\n    for line in config:\n        line = line.strip()\n        if not line or line.startswith(\"#\"):\n            continue\n        key, value = line.split(maxsplit=1)\n        print(key, \"=\", value)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Three loops you can use on a server<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Count HTTP status codes in an access log<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Looping over an open file reads it one line at a time, so this works on a log of any size without loading it all into memory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from collections import Counter\n\nstatuses = Counter()\nwith open(\"\/var\/log\/nginx\/access.log\") as log:\n    for line in log:\n        status = line.split('\"')[2].split()[0]\n        statuses[status] += 1\n\nfor status, count in sorted(statuses.items()):\n    print(status, count)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On our five-line sample log in the standard combined format, it printed <code>200 2<\/code>, <code>404 2<\/code> and <code>500 1<\/code>. Adjust the <code>split()<\/code> if your log format is different.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">List log files and their sizes<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from pathlib import Path\n\nfor path in sorted(Path(\"\/var\/log\/myapp\").glob(\"*.log\")):\n    size_mb = path.stat().st_size \/ 1_000_000\n    print(f\"{path.name}: {size_mb:.1f} MB\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check that your sites answer<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import urllib.request, urllib.error\n\nurls = [\"https:\/\/example.com\/\", \"https:\/\/example.com\/missing.html\"]\nfor url in urls:\n    try:\n        with urllib.request.urlopen(url, timeout=5) as response:\n            print(response.status, url)\n    except urllib.error.HTTPError as e:\n        print(e.code, url)\n    except urllib.error.URLError as e:\n        print(\"DOWN\", url, e.reason)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Against a local test server this printed <code>200<\/code> for the home page, <code>404<\/code> for the missing file and, for a port with nothing listening, <code>DOWN ... [Errno 111] Connection refused<\/code>. The <code>try<\/code> block inside the loop matters: without it, the first failure would stop the whole loop and the remaining sites would never be checked. To run a script like this every few minutes, schedule it with <a href=\"https:\/\/www.ucartz.com\/clients\/knowledgebase\/143\/Setting-a-cron-job.html\">a cron job<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common mistakes and the errors they cause<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Mistake<\/th><th>What Python 3.14 said<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>for i in 10:<\/code><\/td><td><code>TypeError: 'int' object is not iterable<\/code><\/td><td>Use <code>range(10)<\/code><\/td><\/tr><tr><td>Loop body not indented<\/td><td><code>IndentationError: expected an indented block after 'for' statement on line 1<\/code><\/td><td>Indent the body, four spaces is the convention<\/td><\/tr><tr><td><code>range(3)<\/code> over a list with two items<\/td><td><code>IndexError: list index out of range<\/code><\/td><td>Loop over the list itself, or use <code>enumerate()<\/code><\/td><\/tr><tr><td>Removing items from the list you are looping over<\/td><td>No error, but items are skipped<\/td><td>Build a new list instead<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The last one is the sneakiest because nothing crashes. Here we try to remove every port from 8000 upwards:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ports = [22, 80, 8080, 8081, 443]\nfor port in ports:\n    if port &gt;= 8000:\n        ports.remove(port)\nprint(ports)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[22, 80, 8081, 443]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Port 8081 survived. Removing 8080 shifted every later item one place to the left, so the loop stepped straight past 8081. The Python tutorial&#8217;s advice is to loop over a copy or create a new collection. A list comprehension does it in one line and gives the right answer, <code>[22, 80, 443]<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ports = [port for port in ports if port &lt; 8000]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">for or while?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <strong>for<\/strong> when you know what you are looping over: a list, a file, a set number of retries.<\/li>\n\n\n\n<li>Use <strong>while<\/strong> when you loop until a condition changes, such as waiting for a service to come up, and you cannot know in advance how many rounds that takes.<\/li>\n\n\n\n<li>If you only need to build a new list from an old one, a list comprehension is usually shorter and clearer than a loop.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Running your scripts on a server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Scripts like the log counter and the site checker are most useful on the server itself, running on a schedule. Check which Python version your server has with <code>python3 --version<\/code> before you rely on newer features: <code>zip(..., strict=True)<\/code>, for example, arrived in Python 3.10 according to the <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#zip\" target=\"_blank\" rel=\"noopener noreferrer\">built-in functions reference<\/a>. If your script talks to a database, see <a href=\"https:\/\/www.ucartz.com\/clients\/knowledgebase\/64\/How-to-Use-MySQL-From-Python-on-a-cPanel-Server-mysqlclient-and-PyMySQL.html\">how to use MySQL from Python<\/a>, and on a Windows machine, <a href=\"https:\/\/www.ucartz.com\/clients\/knowledgebase\/9285\/How-to-Install-pip-on-Windows-Python-Install-Manager.html\">how to install pip on Windows<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For automation that runs around the clock, a <a href=\"https:\/\/www.ucartz.com\/vps-hosting\">KVM VPS<\/a> gives you full root access to install the Python version and packages you need, and cron or systemd to keep your scripts running.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.<\/p>\n","protected":false},"author":6,"featured_media":3583,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[222,400],"tags":[738,998,931,394,752,996,997],"class_list":["post-3582","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-tutorials-guides","category-tutorials","tag-automation","tag-enumerate","tag-for-loop","tag-linux","tag-python","tag-python-scripting","tag-range"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python for Loop: Syntax and Examples for Server Scripts - Ucartz Blog<\/title>\n<meta name=\"description\" content=\"How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ucartz.com\/blog\/python-for-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python for Loop: Syntax and Examples for Server Scripts - Ucartz Blog\" \/>\n<meta property=\"og:description\" content=\"How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ucartz.com\/blog\/python-for-loop\/\" \/>\n<meta property=\"og:site_name\" content=\"Ucartz Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/UcartzOnline\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-07T14:27:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-07T14:27:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Vipin HP\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ucartz\" \/>\n<meta name=\"twitter:site\" content=\"@ucartz\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vipin HP\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/\"},\"author\":{\"name\":\"Vipin HP\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#\\\/schema\\\/person\\\/5ab7bf96617a036a5d756ba56344b2d8\"},\"headline\":\"Python for Loop: Syntax and Examples for Server Scripts\",\"datePublished\":\"2026-10-07T14:27:03+00:00\",\"dateModified\":\"2026-10-07T14:27:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/\"},\"wordCount\":803,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/python-for-loop.jpg\",\"keywords\":[\"automation\",\"enumerate\",\"for loop\",\"Linux\",\"python\",\"python scripting\",\"range\"],\"articleSection\":[\"Linux Tutorials\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/\",\"url\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/\",\"name\":\"Python for Loop: Syntax and Examples for Server Scripts - Ucartz Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/python-for-loop.jpg\",\"datePublished\":\"2026-10-07T14:27:03+00:00\",\"dateModified\":\"2026-10-07T14:27:12+00:00\",\"description\":\"How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/python-for-loop.jpg\",\"contentUrl\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/python-for-loop.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Python for Loop: Syntax and Examples for Server Scripts\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/python-for-loop\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python for Loop: Syntax and Examples for Server Scripts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/\",\"name\":\"Ucartz Blog\",\"description\":\"Guides on hosting, servers, streaming and automation\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#organization\"},\"alternateName\":\"Ucartz\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#organization\",\"name\":\"Ucartz Online Pvt Ltd\",\"alternateName\":\"Ucartz\",\"url\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/ucartz-logo-888x240-1.png\",\"contentUrl\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/ucartz-logo-888x240-1.png\",\"width\":888,\"height\":240,\"caption\":\"Ucartz Online Pvt Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/UcartzOnline\",\"https:\\\/\\\/x.com\\\/ucartz\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/ucartzonline\",\"https:\\\/\\\/www.instagram.com\\\/ucartz_com\",\"https:\\\/\\\/www.trustpilot.com\\\/review\\\/ucartz.com\",\"https:\\\/\\\/n8n.io\\\/creators\\\/ucartz\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/#\\\/schema\\\/person\\\/5ab7bf96617a036a5d756ba56344b2d8\",\"name\":\"Vipin HP\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6968a0eac95423ae0194661d92ddc9a7774c2c8b34ad6e0977ecb9c119b946cb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6968a0eac95423ae0194661d92ddc9a7774c2c8b34ad6e0977ecb9c119b946cb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6968a0eac95423ae0194661d92ddc9a7774c2c8b34ad6e0977ecb9c119b946cb?s=96&d=mm&r=g\",\"caption\":\"Vipin HP\"},\"description\":\"As a technical content writer, I know that the most effective communication is through a combination of passion and accuracy. My approach is rooted in rigorous research, ensuring accuracy and precision, while also infusing content with a spark of creativity that is engaging and educational.\",\"sameAs\":[\"https:\\\/\\\/www.ucartz.com\"],\"url\":\"https:\\\/\\\/www.ucartz.com\\\/blog\\\/author\\\/vipin-hp\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python for Loop: Syntax and Examples for Server Scripts - Ucartz Blog","description":"How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.","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:\/\/www.ucartz.com\/blog\/python-for-loop\/","og_locale":"en_US","og_type":"article","og_title":"Python for Loop: Syntax and Examples for Server Scripts - Ucartz Blog","og_description":"How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.","og_url":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/","og_site_name":"Ucartz Blog","article_publisher":"https:\/\/www.facebook.com\/UcartzOnline","article_published_time":"2026-10-07T14:27:03+00:00","article_modified_time":"2026-10-07T14:27:12+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop.jpg","type":"image\/jpeg"}],"author":"Vipin HP","twitter_card":"summary_large_image","twitter_creator":"@ucartz","twitter_site":"@ucartz","twitter_misc":{"Written by":"Vipin HP","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#article","isPartOf":{"@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/"},"author":{"name":"Vipin HP","@id":"https:\/\/www.ucartz.com\/blog\/#\/schema\/person\/5ab7bf96617a036a5d756ba56344b2d8"},"headline":"Python for Loop: Syntax and Examples for Server Scripts","datePublished":"2026-10-07T14:27:03+00:00","dateModified":"2026-10-07T14:27:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/"},"wordCount":803,"commentCount":0,"publisher":{"@id":"https:\/\/www.ucartz.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop.jpg","keywords":["automation","enumerate","for loop","Linux","python","python scripting","range"],"articleSection":["Linux Tutorials","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.ucartz.com\/blog\/python-for-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/","url":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/","name":"Python for Loop: Syntax and Examples for Server Scripts - Ucartz Blog","isPartOf":{"@id":"https:\/\/www.ucartz.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#primaryimage"},"image":{"@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop.jpg","datePublished":"2026-10-07T14:27:03+00:00","dateModified":"2026-10-07T14:27:12+00:00","description":"How the Python for loop works: range(), enumerate(), zip(), break, continue and loop else, with tested examples for server scripts and common mistakes.","breadcrumb":{"@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ucartz.com\/blog\/python-for-loop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#primaryimage","url":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop.jpg","contentUrl":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/10\/python-for-loop.jpg","width":1200,"height":630,"caption":"Python for Loop: Syntax and Examples for Server Scripts"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ucartz.com\/blog\/python-for-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ucartz.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python for Loop: Syntax and Examples for Server Scripts"}]},{"@type":"WebSite","@id":"https:\/\/www.ucartz.com\/blog\/#website","url":"https:\/\/www.ucartz.com\/blog\/","name":"Ucartz Blog","description":"Guides on hosting, servers, streaming and automation","publisher":{"@id":"https:\/\/www.ucartz.com\/blog\/#organization"},"alternateName":"Ucartz","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ucartz.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.ucartz.com\/blog\/#organization","name":"Ucartz Online Pvt Ltd","alternateName":"Ucartz","url":"https:\/\/www.ucartz.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ucartz.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/09\/ucartz-logo-888x240-1.png","contentUrl":"https:\/\/www.ucartz.com\/blog\/wp-content\/uploads\/2026\/09\/ucartz-logo-888x240-1.png","width":888,"height":240,"caption":"Ucartz Online Pvt Ltd"},"image":{"@id":"https:\/\/www.ucartz.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/UcartzOnline","https:\/\/x.com\/ucartz","https:\/\/www.linkedin.com\/company\/ucartzonline","https:\/\/www.instagram.com\/ucartz_com","https:\/\/www.trustpilot.com\/review\/ucartz.com","https:\/\/n8n.io\/creators\/ucartz\/"]},{"@type":"Person","@id":"https:\/\/www.ucartz.com\/blog\/#\/schema\/person\/5ab7bf96617a036a5d756ba56344b2d8","name":"Vipin HP","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6968a0eac95423ae0194661d92ddc9a7774c2c8b34ad6e0977ecb9c119b946cb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6968a0eac95423ae0194661d92ddc9a7774c2c8b34ad6e0977ecb9c119b946cb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6968a0eac95423ae0194661d92ddc9a7774c2c8b34ad6e0977ecb9c119b946cb?s=96&d=mm&r=g","caption":"Vipin HP"},"description":"As a technical content writer, I know that the most effective communication is through a combination of passion and accuracy. My approach is rooted in rigorous research, ensuring accuracy and precision, while also infusing content with a spark of creativity that is engaging and educational.","sameAs":["https:\/\/www.ucartz.com"],"url":"https:\/\/www.ucartz.com\/blog\/author\/vipin-hp\/"}]}},"_links":{"self":[{"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/posts\/3582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/comments?post=3582"}],"version-history":[{"count":1,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/posts\/3582\/revisions"}],"predecessor-version":[{"id":3585,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/posts\/3582\/revisions\/3585"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/media\/3583"}],"wp:attachment":[{"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/media?parent=3582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/categories?post=3582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ucartz.com\/blog\/wp-json\/wp\/v2\/tags?post=3582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}