turtle.width() function in Python
This method set or return the line thickness. Set the line thickness to width or return it. If resizemode is set to "auto" and turtleshape is a polygon, that polygon is drawn with the same line thickness. If no argument is given, the current pensize is returned.
Syntax :
tturtle.width(width=None)
# or
turtle.pensize(width=None)
Parameters : width -> Positive number specifying the thickness of the line. Optional; if omitted, the current width is returned.
Returns:
- Current pen thickness (if no argument is provided)
- None (if width is set)
Examples
Example 1 : Setting a fixed line width
import turtle
turtle.forward(100)
turtle.width(4)
turtle.right(90)
turtle.forward(100)
Output :

Explanation: The turtle first draws a line with the default width (usually 1). After setting turtle.width(4), the next line is drawn thicker, with a width of 4.
Example 2 : Changing line width dynamically in a loop
import turtle
for i in range(15):
turtle.width(15-i)
turtle.forward(50+15*i)
turtle.right(90)
Output :

Explanation: The loop draws an expanding spiral where the line width decreases from 15 to 1 while the forward distance increases.