Use Python to answer these questions.

names =[pete, john, paul, george] Explain what Python” src=”” aria-describedby=”hjm”>

3.5. Suppose a list is defined with this assignment statement: >names =[‘pete’, ‘john’, ‘paul’, ‘george’] Explain what Python will print if we ask it to evaluate each of these expressions: a) names [0] b) names[2] c) names [41 d) names[2] george’ == 3.6. Using the same list of names, explain what Python would do if we ask it to evaluate each of the following expressions a) len(names) b) len(names [0]) c) len(names [0] names[1) d) len(names [0]) len(names [1]) 3.7. Do you think Python will let you change an item in a list using an assignment statement? What do you think will happen if you type this expression (assuming names has been defined as above)? >>> names[0]’ringo’ Use a shell session in your IDE to check your answer

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *