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.