import bpy
from mathutils import Matrix
from math import radians
# Create a cylinder object
bpy.ops.mesh.primitive_cylinder_add(radius=1.0, depth=30.0, location=(30.0, 0.0, 15.0))
# Get a reference to the newly created object
obj = bpy.context.active_object
# Create a rotation matrix for a 90 degree rotation around the y-axis
rotation_matrix = Matrix.Rotation(radians(90.0), 4, 'Y')
# Apply the rotation to the object's world matrix
obj.matrix_world @= rotation_matrix
bbb