#loot is an extended command used to open an unlocked container on the floor. Containers in the inventory are opened by applying them. When a bag of tricks is #looted, it will bite you (for 1 to 10 hit points damage) and become identified.
You cannot loot locked containers. You have to first open the lock by either applying some unlocking tool, or breaking the lock with a weapon (using the #force command) or kicking the locked container. However, kicking (or forcing the lock with a blunt weapon) may destroy the contents: you will hear a muffled shatter if any glass object breaks, and a muffled cracking in the case of eggs. Forcing the lock with an edged weapon has a chance of breaking your weapon.
Sometimes looting a container may trigger a trap, such as a poison needle. Use the #untrap command to search the container for traps prior to looting.
The loot command can also be used to remove the saddle from a saddled monster.
If you try to loot when there is no container present, you will be told "You don't find anything here to loot." Furthermore, if you are confused and do this, you will drop some of your gold, and see the message: "Ok, now there is loot here." Attempting to loot a throne while confused generates a throne room monster and deposits a random amount of your gold in its inventory ("The exchequer accepts your contribution"), unless there is a chest on the level, in which case the gold is put in that ("Thank you for your contribution to reduce the debt.")
Loot is also the general name by which the stuff that you have found is called. It is often used in a context like "In addition to the wand, I found lots of nice loot from the Castle." Useless loot is called junk.