<｜begin▁of▁sentence｜>### Instruction:
Given a graph where some nodes may have edges that start and end on themselves, how can you find all nodes with self-loops?
### Response:
import networkx as nx

# Create a graph instance
G = nx.Graph()

# Add edges to the graph
G.add_edge(1, 1)
G.add_edge(1, 2)
G.add_edge(3, 3)

# Use the nodes_with_selfloops API to get nodes with self loops
self_loops = list(nx.nodes_with_selfloops(G))

print('Nodes with self loops:', self_loops)
<|EOT|>
