Learn Liaoche's Python tutorial and find a problem in the loop after class exercises.
name = ['micheal','bob','jack' ] for in name: print(name)print (name) Print (Name[0])
The result of the above code run
What happens to two name,python in this statement? The output of the fourth statement why is Jack? That's what I understand:
Start by creating a list, and then Python points to the list with something named name (think of it as a name pointer to the list would be good to understand), and the list created after initialization comes to the For statement, this time, Python first finds the memory address of the list named name, then applies for generating a variable space and then the thing named name (pointer? the head turns to the newly opened variable space, then Python takes the data out of the list's memory space and stores it in the variable name. So the value of name in line fourth is "Jack", which explains why the output of line fourth is Jack. What is J? I think this is a matter of course, or explain it, after all, this is my first post:-D.
Name="Jack"print(name[0])
The result of the above code is J, name is a string, name[0] is the first to read the name, which is also true in C + +:
#include <iostream>usingnamespace std; int Main () { char * name; Name="Jack"; cout<<name[0]<<endl;}
Well, the first blog to this end, if there is any understanding of the wrong welcome to learn, after all, the purpose of writing a blog in addition to write down the course of the struggle, is to be able to better learn from each other.
Python's variable problem