Python IMDbPY – Checking if person is part of movie or not

In this article we will see how we can check if some person was part of the movie or not, lot of people work to make a movie and some times we don’t know if a person is in that movie or not, but with the help in operator we can check.

Implementation steps :

1. Get the movie data with the help of get_movie method
2. Get the person data with the help of get_person method
3. Using in operator check if person was part of movie or not
4. Show the result

Below is the implementation

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import imdb
  
# creating instance of IMDb
ia = imdb.IMDb()
  
# ID
code = "4434004"
  
# getting movie
movie = ia.get_movie(code)
  
# person id
code2 = "1372788"
  
# getting person
person = ia.get_person(code2)
  
# printing movie object
print(movie)
  
# printing person object
print(person)
  
print("===============")
  
# checking if person is in the movie or not
if person in movie:
    print("Yes !!")
      
else:
    print("No !!")

chevron_right


Output :



Udta Punjab
Shahid Kapoor
===============
Yes!!

Another example

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import imdb
  
# creating instance of IMDb
ia = imdb.IMDb()
  
# ID
code = "1187043"
  
# getting movie
movie = ia.get_movie(code)
  
# person id
code2 = "1372788"
  
# getting person
person = ia.get_person(code2)
  
# printing movie object
print(movie)
  
# printing person object
print(person)
  
print("===============")
  
# checking if person is in the movie or not
if person in movie:
    print("Yes !!")
      
else:
    print("No !!")

chevron_right


Output :

3 Idiots
Shahid Kapoor
===============
No!!

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.