How to assign product attribute to attribute set Magento 2?

Product attributes will be displayed in the product admin page by assigning an attribute to specific attribute set groups from the attribute set section in the backend.

You can manually set an attribute to the attribute group by click on Left sidebar, Stores -> Attributes ->Attribute Set.
Click on Any attribute set and drag and drop attribute from the Unassigned Attributes section to Groups section.

We can assign an attribute to attribute set programmatically using the interface, Magento\Catalog\Api\ProductAttributeManagementInterface

Base Definition of the method to assign attribute,

$attributeSetId indicate Attribute set id.
$attributeGroupId indicate Attribute group id.
$attributeCode indicates the attribute code you want to assign to a specific attribute group.
$sortOrder indicates the sort order of the attribute in the group from the list of the attribute of the same attribute group.

You need to pass the required parameter in the above method to assign the attribute to your required attribute group.
Call from the template or any PHP class,

attribute assign
Attribute assign to attribute set

Output:
int on assigned attribute successful.