order . For example, call Enroll (' Adam ', ' M ', city= ' Tianjin '), meaning that the city parameter uses the values passed in, and the other default parameters continue to use the default values.
Variable parameters can be directly passed in: Func (1, 2, 3), can be assembled first list or tuple, and then passed through the *args: Func (* (1, 2, 3));
Keyword parameters can be passed directly into: Func (A=1, b=2), can be assembled dict first, and then passed **kw to: func (**{' a ': 1, ' B ':
1. Default value parameter
That is, the default value is set for the function parameter, when the function is called, the default value parameter is not passed, the defaults are invoked automatically, and the replaced argument is used if the parameter values for the default value are set.
You can use ' function name. Func_defaults ' (use '
directoryeg : Create a test directory under the system D drive>>> Import OS>>> os.mkdir (' d:\\test ')5 , Os.removedirs () function Function: Delete the specified directoryeg : Delete Test directory under D drive>>> Import OS>>> os.removedirs (' d:\\test ')6 , Os.remove () function Function: Delete the specified filee
#-*-coding:utf-8-*-
#偏函数
#字符串转整型, default to 10-in
print int (' 12345 ')
#10进制
print int (' 12345 ', base=10)
#8进制 Print int ('
12345 ', base=8)
#2进制 print int ('
10000 ', base=2)
#16进制
print int (' 12345 '), base=16)
'
from the above:
int function has default parameter base=10.
How to create a base=16
default parameter function
'
def int16 (x) on a secondary basis: return
int (x,base=16)
print int16
Recently, I encountered a problem when writing a python application: When a module is introduced, a custom int is automatically introduced to the namespace of python, which overwrites the intfunction that comes with python. because we need to use the python int, we have to find the method to re-introduce this int. fort
by name
4. Parameters of the functionFormal parameter types that can be used when calling a function:
Position parameters
Keyword parameters
Default parameters
Indefinite length parameter
Position parametersPositional parameters, also called required parameters, must be passed to the position parameter when the function is called, and must be passed in in the correct order an
Detailed description of Python Implementation of the function of pressing any key to continue/exit, detailed description of python
Preface
To implement this function, you need to pause the program, wait and capture a user's keyboard input, and then continue to execute. Python
Python exception handling-raise function usage, python-raise
The raise statement manually raises an exception:
1 "raise" [expression ["," expression ["," expression]
In Python, to cause an exception, enter the keyword raise, followed by the name of the exception to be thrown. Exception names identify specific cl
, 5, 1, 7]List (map (lambda x:abs (x), my_list)Return:[3, 4, 2, 5, 1, 7]Other functions (with/without parameters) can be called from within a lambda function.def foo (msg): Print Lambda"helloWorld": foo (x) greet ()Print:Hello WorldBecause this is very useful lambda can only contain one expression and can run multiple statements by using one of the subordinate functions. AttentionRemember, PEP-8 ( The official Python style guide) does not reco
First, Python decoratorDefinition: The essence is the function (decoration of other functions), for other functions to add attachment function.Follow the principle: ① cannot modify the source code of the decorated function② cannot modify the calling method of the decorated functionComposition: adorners consist of higher order functions + inline functions + closur
Detailed explanation of the full match function using regular expressions in python, python Regular Expressions
Full matching using regular expressions in python
There are many matches in python, such as the search () function at
", name,end="'); - Print("and my age is", age,end="'); $ thestudent={"name":"Jack"," Age": 25}; theParrot (* *student); the thestu=["Jack", 25]; -Parrot (*Stu); in the #pairs = [(1, ' One '), (2, ' One '), (3, ' three '), (4, ' four ')] the #Pairs.sort (Key=lambda pair:pair[1]) About the #the use of the LAMDA expression is the inverse name function the defSorter (l=None): the ifL isNone: +L=[]; -L.sort (key=LambdaPair:pair[1]); the
1. ABS (): Returns the absolute value of the given parameter. If the argument is a complex number, it returns the modulus of the complex number, that is, the square root of the sum of the real and imaginary parts of the complex number:>>>abs ( -1)1>>>abs ( -56.78e-2)0.5678>>> (3+4j)5.02.coerce () (function in Python 2): Returns an element tuple containing two numeric values for the type conversion:>>>coerce
Python sorted function, pythonsorted Function
I learned about socket programming two days ago and was disgusted when I asked a great God a question. There is a feeling that I want to run without learning to go. The great God said that I should do some small exercises like Operating Files and serial numbers to deepen my understanding. The following is a small exer
Python standard library: built-in function filter (function, iterable), pythoniterable
This function is used to traverse all elements from an iteration object iterable. When each element is run on the function object as a parameter, the elements that are judged to be True a
Exercise one: Hit all the even numbers between 1-100Def even_print (): For I in range (1,101): If I% 2 = = 0: print (i) even_print ()Exercise two: Design a function, create 10 files on the desktop, and name them as numbersDef text_creation (): path = ' c:/users/administrator/desktop ' for name in range (1,11): With open (path + str ( Name) + ' txt ', ' W ') as text: text.write (str (name)) text.c
*Self.height the Print('length =', Self.length,'width =', Self.width,'height =', Self.height,'valum=', self.__valum) - - defInfo_color (self): - #Self.set_color (Self._color) #在类中, the way function calls functions + Print('The color of box is', Self._color) - + defOpen_box (self): A ifbox.openstate==0: at Print('Open the box.') -Box.openstate=1 - Else: - Print('The box is open a
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.