A solenoid is a long coil of circular loops of insulated copper wire. Magnetic field lines are produced around the solenoid when a current is allowed to flow through it. The magnetic field produced by it is similar to the magnetic field of a bar magnet. The field lines produced in a current-carrying solenoid is shown in the following figure.
In the above figure, when the north pole of a bar magnet is brought near the end connected to the negative terminal of the battery, the solenoid repels the bar magnet. Since like poles repel each other, the end connected to the negative terminal of the battery behaves as the north pole of the solenoid and the other end behaves as a south pole. Hence, one end of the solenoid behaves as a north pole and the other end behaves as a south pole.