Python argparse
You want the screen to show one word you put after the program name. You will put lamp after the name. The line on the screen will be lamp.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("item")
args = parser.parse_args()
print(args.item)
The screen shows lamp. lamp is the word you put after the program name. lamp is not written in the program. parser.add_argument("item") names the place that word goes. args = parser.parse_args() reads the word you put after the name. print(args.item) writes lamp. The program is done. There is no second line.
If you put cord after the name, the screen is cord. That run is not this one. This run puts lamp after the name, so the screen is lamp.
You can now read one word you put after the program name and show that word on the screen. This screen is lamp. This is the last page.
The screen is the word after the name
The screen is lamp. lamp is not written in the program. This is the last page.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top