A pen cost $4 and a book costs $7. Sam paid $64 for 10 such pens and books. Find the number of pens and the number of books he had bought.

Let's assume the number of pens that Sam bought is "x".

Therefore, the number of books that Sam bought would be "10 - x".

The cost of x pens would be 4x dollars.
Similarly, the cost of (10 - x) books would be 7(10 - x) dollars.

Since the total cost was $64, we can create the equation:
4x + 7(10 - x) = 64

Expanding the equation, we get:
4x + 70 - 7x = 64
-3x + 70 = 64

Subtracting 70 from both sides:
-3x = -6

Dividing both sides by -3:
x = 2

Therefore, Sam bought 2 pens and the number of books he bought is 10 - 2 = <<10-2=8>>8. Answer: \boxed{2, 8}.