My Love Python group Friends questions and answers

Source: Internet
Author: User

1, first a group of friends to ask such questions

This error is obvious, the object of type int is not supported by iteration, this is obvious. The solution given is also very simple, just to change the int type number to the STR type.

2, the group friend said that his tuple may have any type of data, the above method may not apply, and then he gave an example, said the data is this

Again int type cannot iterate error, is the parameter passed in is not c[0]? But what?

3, it appears in the above map (List,c[0]) passed in the list of parameters is really not c[0], we need to learn what the map what the hell? Let's take a look at the map's help document

Let's just look at the first sentence, it is the parameter list of the various items using function functions, and finally output a list of results. Give a simple example to explain this sentence,

First, an add function is defined, and the argument list is [2,3,4], so the actual value of each incoming add () function is a value in the argument list, not the parameter list itself, and is run iteratively.

So map (List,c[0]), the actual incoming list is the number 1 in c[0], and list (1) is wrong.

In fact the group of friends wanted the result is [[1, ' Zhang '],[2, ' san '], so the correct wording is map (list,c)

My Love Python group Friends questions and answers

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.