Understand:method is called with ().To be more abstract, the method is a variable name, and "()" is a simple representation of the calling method (also for the compiler to recognize), and the calling method is the result of the operation.Eg:a = 1; A is a variable name, and "=" is a simple expression of the assignment (but we have been in touch with the language for too long and the subconscious has assumed that = is the assignment.) But in fact, "=" into the @, replaced by "assignment", and what
strings, numbers, lists, tuples, dictionariesVariable non-volatile1. Variable: ListSuch as:>>> a = ["123", "xiaoxing"]>>> ID (a)4314085280>>> a[0] = "Ceshi">>> ID (a)4314085280>>> Here we first assign a value to the list A, get the ID (a), that is, the memory address is 4314085280After we modify the value of the element in List A, the memory address of the re-acquisition of a is still unchanged, but the internal value has been modified, so the list is mutable.2. Immutable: string, number, tupleT
list:>>> a=[[1,2,3],[4,5,6],[7,8,9]]>>> [[Sublist[i]+1 for I in range (3)] for sublist in a][[2, 3, 4], [5, 6, 7], [8, 9, 10]]>>>If we were to imagine a two-dimensional array as inverted arrays, that is, I want to a=[[1,2,3],[4,5,6],[7,8,9]] [[1,4,7],[2,5,8],[3,6,9]], we can do this:>>> a=[[1,2,3],[4,5,6],[7,8,9]]>>> [[Sublist[i] for sublist inch A] for I in range (3)][[1, 4, 7], [2, 5, 8], [3, 6, 9]]The above code can also be replaced with the following code:>>> x=[[],[],[]]>>> a=[[1,2,3],[4,5
Chapter One: Basic knowledge1. Double slash: The operator that implements the divide>>>1//20Even if it is a floating-point number, the slash will perform the divide>>>1.0//2.00.02. Power (exponentiation) operator: Double star>>>2**38Tip: You can use the function POW instead of the operator, pow (2,3)3.16 Binary and octalHex: Front plus 0x, first is number 0>>>0xaf175Octal: Add 0o to Python in version 3.0, the first number is 0, the second is the lette
#列表可修改, the Yuan Zu cannota=['sdsd',]b=['SDS',]c=[a,b]#分片 :-#list函数#分片赋值#列表方法Lst.append (4) X.count (1) x.count ([up]) A.extend (b) a.index ("w" ) A.insert (3, "all")X.removeX.reverseX.sort#pop removes the list element and returns a value. Implementation data structure-stack, LIFO (LIFO), X.append (X.pop ()), FIFO, X.insert (X.pop (0)#sortX.sort (Key=len)y=sorted (x)#y元祖No list-like methods(a)#tuple函数# become a meta-ancestorPython Basic Learning Note
#模块#包#模块中有什么Dir L List features#文档Print range.__doc__#阅读源代码Print copy.__file__#标准库Sysosfileinput#集合, heap and double-ended queuesSet (range) Thecollection heap data structure is not independent of only one module containing some heap operations, called HEAPQ (6 functions) Double-ended queue#time#random#shelve#re# contains support for regular expressionsPython Basic Learning Note--python Basic Tutorial (2nd
functions. For example: POW is used to calculate standard functions such as Solutionkeys GT;GT;GT;2**38GT;GT;GT;POW (2.3) 8pow, called built-in functions, or you can customize functions. The 1.9 module can be thought of as an extension that imports into Python to enhance its functionality and is imported using the Import command. For example: Import the Math module with import and use >>>importmath>>>math.floor (32.9) in the format "module. function"
"Basic Python Tutorial (second edition)" Learning notesBasic part (1th chapter)IdeWindows:idle (GUI), Eclipse+pydev; Python (command line);Linux/unix:python>>> 1/2=0 note divisible by 0.>>> from __future__ Import Division performing normal divisionPython-qnew Perform a normal divisionDivide, 1//2=0;% take the remainder
Basic Python Tutorial (second edition) Learning Note Strings (Chapter 3rd)All basic sequence Operations (index, Shard, multiply, Judge membership, seek length, maximum minimum) also apply to strings.The string is not to be changed;The left side is the format string, and the right side is the value that needs to be formattedprint '%s=%d '% (' x ', ') ==> x=100% in
Basic Python Tutorial (second edition) Learning note files and materials (11th)Open File:Open (Filename[,mode[,buffering]])Mode is the pattern of reading and writing filesF=open (R ' c:\somefile.txt ') #默认是读模式+ means can read and write, R read mode, W write mode, a append mode, b binary mode;The newline character is \ r \ n in Windows, and in Unix,
Basic Python Tutorial (second edition) Learning Note function (Chapter 6th)To create a function:def function_name (params):BlockReturn valuesRecord function:def function_name (params):' NOTE ' #注释BlockReturn valuesfunction_name.__doc__Help (Function_name)Return # no value returnedPosition parameters and keyword parameters:Keyword parameter to provide the name of
() if user== Username and Passwd==password:print ("\033[32;1muser has passed authentication\033[0m") Res=func (*args,**kwargs) # print ("---after authentication---") #保留要装饰函数home的输出结果 r Eturn Res else:exit ("\033[31;1minvalid username or password\033[0m") elif au th_type== "LDAP": Print ("Engage the yarn LDAP, will not ....") ") return wrapper return Outer_authdef index (): Print (" Welcome to Index page ") @auth (auth_type=" local ") def Hom E (): Print ("Welcome to Home Pag
draws a section to explain how to debug a program. The author summarizes all aspects of debugging, focusing on the language features of each chapter, or related development issues.The 2nd and 1th editions of the book have made a lot of updates, upgrading the programming language from Python 2 to Python 3, and modifying a lot of examples and exercises, adding new chapters and a more comprehensive introducti
"core" content of the language, including basic concepts and statements, syntax and style, Python objects, number types, sequence types, mappings and collection types, conditions and loops, files and inputs/outputs, errors and exceptions, Functions and functional programming, modules, object-oriented programming, execution environments, and more: Part 2nd provides a variety of advanced topics to show what you can do with
of the space, explaining the "core" content of the language, including basic concepts and statements, syntax and style, Python objects, number types, sequence types, mappings and collection types, conditions and loops, files and inputs/outputs, errors and exceptions, Functions and functional programming, modules, object-oriented programming, execution environments, and more: Part 2nd provides a variety of advanced topics to show what you can do with
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.