Python's variable problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.