Python basic knowledge of the whole network the most complete 4 (function file)

Fourth, the function

  • 1. The function definition
    Example 1:
def MyFirstFunction():
     print('Hello World!')

Example 2:

def add(num1,num2):
     #函数定义过程中,num1,num2是形参’      #注释1 #文档
     #因为它只是一个形式       //注释2
     return (num1 + num2)  

Example 3:

def demo1(a = 'hello',b='world'):
     print(a +->+ b);
     #如果函数调用没有传递参数,就使用默认值4.
```python
def demo2(*param):
     print()
  • 2. The function call :
add(1,2)    结果: 3  
add(num1=1,num2=2)   结果: 3
add.__doc__          #函数定义过程中,num1,num2是形参’ 

Fifth, file

Open mode

  • 1.open():

open (the file path, opening mode): in the specified mode (above table) to read the specified file (\ slash to be escaped).
If the file to be read with this .py file in the same directory, direct write the file name on the line

  • 2. File object methods

File object methods

Guess you like

Origin blog.csdn.net/affluent6/article/details/91534225