How can I arrange items in a circle using Python? I wrote this code with the intention of getting a square arrangement of pillars.

for i in range(0,9):
    for j in range(0,9):
        x = i
        y = j
        z = 0.5
        bpy.ops.mesh.primitive_cube_add(location=(x,y,z))
        cube = context.active_object
        cube.scale[0] = 0.3
        cube.scale[1] = 0.05
        cube.scale[2] = 0.8
        scene.objects.link(cube)


I'm unsure how I would get the cubes to arrange themselves in a circular pattern. I know that I can set z = 0 (all cubes on the same plane), and that x and y should satisfy the equation of a circle, x^2+y^2 = radius^2; but I'm unsure how to best proceed. Could anyone please lend me a hand?

Thank you in advance!
Could use the polar coordinates r and theta, where x = r * cos(theta) and y = r * sin(theta)

eg below, a full circle with 60 pillars. Like minutes on a clock.


import bpy
context = bpy.context
scene = context.scene
from mathutils import Matrix
from math import radians, sin, cos
z = 0.5
r = 4
theta = radians(360) # 2Pi
columns = 60
alpha = theta / columns
for a in range(columns):
    angle = a * alpha
    x = r * cos(angle)
    y = r * sin(angle)
    bpy.ops.mesh.primitive_cube_add(location=(x,y,z))
    cube = scene.objects.active
    # rotate if needed
    #cube.rotation_euler.z = angle # or using Matrix
    rotmat = Matrix.Rotation(angle, 4, 'Z')
    cube.matrix_world *= rotmat

    cube.scale = (0.3, 0.05, 0.8)