The function of a transistor in an electronic circuit is to amplify or switch electronic signals and electrical power. Transistors control the flow of current in a circuit, acting as either an amplifier or a switch. In amplification, transistors are used to increase the strength of weak signals, making them suitable for driving speakers, powering motors, etc. In switching, transistors control the flow of current by either allowing or blocking it, facilitating binary digital functions like turning on or off a device, making logical decisions, etc. Transistors play a crucial role in modern electronics, being a fundamental building block in various electronic devices like computers, televisions, radios, and many others.