Explanation:
You can try to expand, then you will get the middle term as 2ab or -2ab:
(a+b)² = (a+b)(a+b)
= a² + ab + ab + b²
= a² + 2ab + b²
As for the (a-b)², it will come in the same way :
(a-b)² = (a-b)(a-b)
= a² - ab - ab + b²
= a² - 2ab + b²
(Hope you can understand)