title: What does next() and iter() do in PyTorch's DataLoader()
body: <p>I have the following code:</p>
  <pre><code>import torch
  import numpy as np
  import pandas as pd
  from torch.utils.data import TensorDataset, DataLoader
  
  # Load dataset
  df = pd.read_csv(r'../iris.csv')
  
  # Extract features and target
  data = df.drop('target',axis=1).values
  labels = df['target'].values
  
  # Create tensor dataset
  iris = TensorDataset(torch.FloatTensor(data),torch.LongTensor(labels))
  
  # Create random batches
  iris_loader = DataLoader(iris, batch_size=105, shuffle=True)
  
  next(iter(iris_loader))
  </code></pre>
  <p>What does <code>next()</code> and <code>iter()</code> do in the above code? I have went through <a href="https://pytorch.org/docs/stable/data.html#:%7E:text=Data%20loader.,(collation)%20and%20memory%20pinning." rel="noreferrer">PyTorch's documentation</a> and still can quite understand what is <code>next()</code> and <code>iter()</code> doing here. Can anyone help in explaining this? Many thanks in advance.</p>