x = [1, 2, 3]
y = x
x[1] = 'AB'
y[1] = y[1][0]
print(x, y)
>>>
[1, 'A', 3] [1, 'A', 3]
We assign ‘AB’ value to index 1 for x list so y list gets this value as well. Then we assign y[1][0] value to y[1], but what does y[1][0] notation mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
y[1]is the second item from your list, that is ‘AB’ which is a string. As strings allow you to access its values with indexes,y[1][0]is just the first item from the string ‘AB’, that is ‘A’.See this for an introduction to Python’s strings and slice notation.