Python 3.4 - Membership and Identity Operators

Membership operators check to see if an object is present. using the in function one can determine if an object exists in a data set.

data = "My name is Matt"
"name" in data
True 
 
You can use is or == to determine if a variable is using the same object reference. You may also use the is not to determine if two variables are using the same object reference.


my_list = ['john', 'matt', 'rick', 'jehovah', 'buddha']
my_list2 = ['john', 'matt', 'rick', 'jehovah', 'buddha']

if 'dog' in my_list:
    print('hello')
else:
    print('not in the list')

    ## the in operator checks to see if the value dog is in the list.

if my_list == my_list2:
    print('they are the same') ## this checks to see if they are the same.

/Users/mattfassnacht/PycharmProjects/untitled10/venv/bin/python /Users/mattfassnacht/PycharmProjects/untitled10/math.py
not in the list
they are the same

Process finished with exit code 0


https://www.youtube.com/watch?v=aaBYOzR9uZo

Comments

Popular posts from this blog

Pyhton 3.4 - Continue

Conversations Ongoing: Valuing Modernization in Early European History

Conversations Ongoing: A Bunch of Amateurs