Head First Python Study Notes 1, python Study Notes

Source: Internet
Author: User

Head First Python Study Notes 1, python Study Notes

# Recursive def recursion (movies): for item in movies: # isinstance is a judgment type function if isinstance (item, list): recursion (item) else: print (item )#

I am learning python and record it. It seems that this book is not very suitable for people without programming basics. Let's talk about the problem of list and recursion.
Python is a dynamic language, that is, the type does not need to be declared (like List or int in C #). For example, to declare a List, you can directly movies = ["Return of the secret of travel to the West ", "Jurassic World", 1, ["Penguins in Madagascar"], the list is nested here, so the next step is to traverse the list recursively.

After learning c #, I think the above Code is quite understandable. def is the keyword for declaring a function, and the parameters in the brackets are .. in ..: similar to the foreach loop in c #, and then checks whether it is a list using isinstance. If yes, the function is called again. This is a typical recursion.

Once again, I spoke about it: Is this really an introductory tutorial? If you don't introduce the data type and some basic keywords, you can solve the problem directly (the book aims to solve the problem: Someone has collected a lot of movie data, need to manage), think about it, it seems to be good, that is, people who have no programming foundation can suffer.

Then, package the code into a module and release it (I feel a little unable to keep up with it). The module is a bit like a dll in c.

First create a folder, save the source code to the value folder, and then add a new setup. py file,

From distutils. core import setupsetup (name = 'program name', version = '1. 0.0 ', py_modules = ['module name'], author = 'author', author_email = 'mailbox @ gmail.com ', url = '', description = 'a simple recursion ',)

Then enter the folder in the command line and run: python setup. py sdist to package your module. After packaging, install python setup. py. At this time, enter the IDLE to use the import (equivalent to the Using keyword in C #) to import the module, and then use the module name to call the function.

 

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.