Hannah wanted a son, but she could not conceive. Therefore, she prayed to the Lord for a son, and He heard her, giving her Samuel. That moved her to praise the Lord. Read part of what she said,
“Those who were full have hired themselves out for bread,
And the hungry have ceased to hunger.
Even the barren has borne seven,
And she who has many children has become feeble.”
(First Samuel 2.5)
No doubt she attached significance to the number seven, because she spoke intentionally and poetically in praising God. She praised God because He could enable a barren woman, such as herself, suddenly have the ability to conceive and even to bear seven children, a perfect number, showing the perfection of our God in answering prayer.