title: What does asyncio.create_task() do?
body: <p>What does <code>asyncio.create_task()</code> do? I have looked at the docs and can't seem to understand it. A bit of code that confuses me is this:</p>
  <pre class="lang-py prettyprint-override"><code>import asyncio
  
  async def counter_loop(x, n):
      for i in range(1, n + 1):
          print(f&quot;Counter {x}: {i}&quot;)
          await asyncio.sleep(0.5)
      return f&quot;Finished {x} in {n}&quot;
  
  async def main():
      slow_task = asyncio.create_task(counter_loop(&quot;Slow&quot;, 4))
      fast_coro = counter_loop(&quot;Fast&quot;, 2)
  
      print(&quot;Awaiting Fast&quot;)
      fast_val = await fast_coro
      print(&quot;Finished Fast&quot;)
  
      print(&quot;Awaiting Slow&quot;)
      slow_val = await slow_task
      print(&quot;Finished Slow&quot;)
  
      print(f&quot;{fast_val}, {slow_val}&quot;)
  
  asyncio.run(main())
  </code></pre>
  <p>This gives the following output:</p>
  <pre><code>001 | Awaiting Fast
  002 | Counter Fast: 1
  003 | Counter Slow: 1
  004 | Counter Fast: 2
  005 | Counter Slow: 2
  006 | Finished Fast
  007 | Awaiting Slow
  008 | Counter Slow: 3
  009 | Counter Slow: 4
  010 | Finished Slow
  011 | Finished Fast in 2, Finished Slow in 4
  </code></pre>
  <p>I don't understand quite how this is working.</p>
  <ol>
  <li>Shouldn't the <code>slow_task</code> not be able to run until the completion of
  the <code>fast_coro</code> because it was never used in an <code>asyncio.gather</code>
  method?</li>
  <li>Why do we have to <code>await slow_task</code>?</li>
  <li>Why is <code>Awaiting Slow</code> printed after the coroutine appears to have started?</li>
  <li>What really is a <em>task</em>? I know that what <code>gather</code> is doing is scheduling a
  <em>task</em>. And <code>create_task</code> supposedly creates a task.</li>
  </ol>
  <p>An in-depth answer would be greatly appreciated. Thanks!</p>
  <p>It also might be worth mentioning that I know very little about Futures.</p>