The prime minister of Canada has apologised for wearing black make-up and understands that dressing up in blackface was racist.