Discussion Forum Unit 6 CS1101 - Python PDF

Title Discussion Forum Unit 6 CS1101 - Python
Author Simo Renato
Course Cs Terms
Institution University of the People
Pages 2
File Size 32.8 KB
File Type PDF
Total Downloads 13
Total Views 132

Summary

great tips for getting on with your discussion and also a better understanding when you are rating your peers...


Description

Part 1. # in python, Strings and lists are all objects but their values may or may not be the same. # For instance, two or more variables may be assigned the same string which makes them equivalent # but, when two or more variables are assigned the same list they are only identical and not equivalent # Here, the is operator can only return True if the values of the variables are equivalent (string) # and False when they are only identical (list)

# Example1: equvilent variables x = "Example" y = "Example" >>> *** Remote Interpreter Reinitialized *** >>> x is y True # Example2: Identical variables a = ['The', 'Lazy', 'Dog'] b = ['The', 'Lazy', 'Dog'] >>> *** Remote Interpreter Reinitialized *** >>> a is b False

Part 2. # the relationship between objects, references and aliases is that objects like strings or list can be referred to from different variables. The easy way to do this is to create an alias; meaning that when you set a variable equal to another variable and its list items, then you have created an alias for that list. Thus, the two variables will always refer to the same list. Example: c = ['The', 'Lazy', 'Dog'] d=c >>>

*** Remote Interpreter Reinitialized *** >>> c is d True # Notice that the output is “True” because c and d now refer to the same object. Also, we can term it as aliasing because d is an alias of c. Part 3. def append_list(articles: list):# Function Parameter articles.append('Eggs') # Function argument a = ['Flour', 'Milk', 'Sugar'] # Objects to refer to append_list(a) # a now refers to the objects in the article list print(a)

>>> *** Remote Interpreter Reinitialized *** ['Flour', 'Milk', 'Sugar', 'Eggs'] >>>...


Similar Free PDFs