[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/coding336/Python/master/python6/4.md [Back]  [Original]

#  #

## 1 ##



```python
# -*- coding: UTF-8 -*-

def print_user_info( name , age , sex = '' ):
    # 
    print('{}'.format(name) , end = ' ')
    print('{}'.format(age) , end = ' ')
    print('{}'.format(sex))
    return;

#  print_user_info 

print_user_info( '' , 18 , '')
print_user_info( '' , 25 )
```



```txt
 18 
 25 
```

****def func(a, b=1)  def func(a=1, b)    

 lsit  dict  None 

```python
#  b  list  None 
def print_info( a , b = None ):
    if b is None :
        b=[]
    return;
```

 `b=[]` 

```python
def print_info( a , b = [] ):
    return;
```
**NoneTrueFalse**



```python
# -*- coding: UTF-8 -*-

def print_info( a , b = [] ):
    print(b)
    return b ;

result = print_info(1)

result.append('error')

print_info(2)
```



```txt
[]
['error']
```






```python
_no_value =object()

def print_info( a , b = _no_value ):
    if b is _no_value :
        print('b ')
    return;
```
 `object` python  `object`  () 

## 2 ##

 Python  





```python
# -*- coding: UTF-8 -*-

def print_user_info( name ,  age  , sex = '' ):
    # 
    print('{}'.format(name) , end = ' ')
    print('{}'.format(age) , end = ' ')
    print('{}'.format(sex))
    return;

#  print_user_info 

print_user_info( name = '' ,age = 18 , sex = '')
print_user_info( name = '' ,sex = '', age = 18 )

```



```txt
 18 
 18 
```

## 3 ##


Python  `*` 



```python
# -*- coding: UTF-8 -*-

def print_user_info( name ,  age  , sex = '' , * hobby):
    # 
    print('{}'.format(name) , end = ' ')
    print('{}'.format(age) , end = ' ')
    print('{}'.format(sex) ,end = ' ' )
    print('{}'.format(hobby))
    return;

#  print_user_info 
print_user_info( '' ,18 , '', '','','')

```



```python
 18  ('', '', '')
```

`*hobby` hobby tuple 


 `**`,


```python
# -*- coding: UTF-8 -*-

def print_user_info( name ,  age  , sex = '' , ** hobby ):
    # 
    print('{}'.format(name) , end = ' ')
    print('{}'.format(age) , end = ' ')
    print('{}'.format(sex) ,end = ' ' )
    print('{}'.format(hobby))
    return;

#  print_user_info 
print_user_info( name = '' , age = 18 , sex = '', hobby = ('','',''))

```



```txt
 18  {'hobby': ('', '', '')}	
```

`*hobby` hobby tuple `**hobby` hobby  dict 


## 4 ##



`*``*`,

```python
# -*- coding: UTF-8 -*-

def print_user_info( name , *, age  , sex = '' ):
    # 
    print('{}'.format(name) , end = ' ')
    print('{}'.format(age) , end = ' ')
    print('{}'.format(sex))
    return;

#  print_user_info 
print_user_info( name = '' ,age = 18 , sex = '' )

#  age sex 
#print_user_info( '' , 18 , '' )
print_user_info('',age='22',sex='')
```

 `age` , `sex` 

 `**kw` 

Web Proxy Viewer  |  New URL  |  Original Page