check if camera is being used python

cap = cv2.VideoCapture(0)
# the variable before frame is True if the camera is useable
useable, frame =

Here is what the above code is Doing:
1. We’re creating a VideoCapture object. Its argument can be either the name of a file or a camera index. If we pass a camera index to VideoCapture, it will open the default camera with that index. If we pass the name of a video file, it will open that video file.
2. We’re calling the read method of the VideoCapture object. This returns a tuple. The first element of the tuple is a Boolean indicating whether or not the frame was read correctly. The second element of the tuple is the frame itself.
3. If the frame was read correctly, we process it. Otherwise, we print an error message.