You likely would lose weight
with a diet
of only carrots - but your health would suffer as carrots do not contain all the necessary nutrients to maintain your health.
You are correct in thinking that the key to weight loss is dietary constraint - but you should observe a well balanced diet that restricts total caloric intake in order to lose weight safely. See a dietician for guidance.