The Magificat or the Canticle of Mary (Luke 1:46-56) mirrors Hannah's prayer 1 Samuel 2:1-10 so closely that one would have to think that Mary found her words in through reflecting on scripture.
And Hannah prayed: And Mary said:
My heart exults in the LORD, “My soul proclaims the greatness of the Lord;
my horn is exalted by my God. my spirit rejoices in God my savior
For he has looked upon his handmaid’s lowliness;
behold, from now on will all ages call me blessed.
The Mighty One has done great things for me,
and holy is his name
His mercy is from age to age
to those who fear him.
I have swallowed up my enemies;
I rejoice in your victory.
There is no Holy One like the LORD;
there is no Rock like our God.
Speak boastfully no longer,
Do not let arrogance issue from your mouths.
For an all-knowing God is the LORD,
a God who weighs actions.
“The bows of the mighty are broken, He has shown might with his arm,
while the tottering gird on strength. dispersed the arrogant of mind and heart.
The well-fed hire themselves out for bread, He has thrown down the rulers from their thrones
but lifted up the lowly
while the hungry no longer have to toil. The hungry he has filled with good things;
the rich he has sent away empty
The barren wife bears seven sons,
while the mother of many languishes.
“The LORD puts to death and gives life,
casts down to Sheol and brings up again.
The LORD makes poor and makes rich,
humbles, and also exalts.
He raises the needy from the dust;
from the ash heap lifts up the poor,
To seat them with nobles
and make a glorious throne their heritage.
“For the pillars of the earth are the LORD’s,
and he has set the world upon them.
He guards the footsteps of his faithful ones, He has helped Israel his servant,
remembering his mercy,
but the wicked shall perish in the darkness;
for not by strength does one prevail.
The LORD’s foes shall be shattered;
the Most High in heaven thunders;
the LORD judges the ends of the earth.
May he give strength to his king,
and exalt the horn of his anointed!”
according to his promise to our fathers,
to Abraham and to his descendants forever.”
That scripture, which would have been burned in to her Immaculate Heart, by means of a singular grace would have certainly been with her at a young age when she would be betrothed. One tradition (not Sacred Tradition), which is mostly forgotten by popular imagery, is in that Catholic Encyclopedia article Drew linked to which says that Mary was a consecrated virgin raised in the temple, that her parents Anne and Joachim prayed for her and when they got her, gave her up to the temple where she would have been able to absorb scripture like Anna (Luke 2:36-38), who would have certainly known all about her if that were the case.