001 print输出函数
print ( 123 )
print ( "文字" )
print ( [ 1 , 2 , 3 ] )
print ( 1 + 1 )
outStream = open ( r"E:\Software\JetBrainsIDEA\PythonIDEA\Projects\CXSJS\Python\Python学习\01输出函数\print.txt" , "a+" )
print ( "hello world" , file = outStream)
outStream. close( )
print ( "Java" , "C++" , "Python" )
print ( "hello world" , end= " 自定义结束符号" )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
002 转义字符
print ( "hello\nworld" )
print ( "hello\tworld" )
print ( "hello\rworld" )
print ( "hello\bworld" )
print ( "\\" )
print ( "\'" )
print ( r"\\" )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
print ( chr ( 0b100111001011000 ) )
print ( ord ( "乘" ) )
004 变量的定义与使用
name = "玛卡巴卡"
print ( "标识" , id ( name) )
print ( "类型" , type ( name) )
print ( "值" , name)
name = "唐伯利伯"
print ( "新的值" , name)
005 整数类型
n1 = 90
n2 = - 76
n3 = 0
print ( n1, type ( n1) )
print ( n2, type ( n2) )
print ( n3, type ( n3) )
print ( '十进制' , 118 )
print ( '二进制' , 0b10101111 )
print ( '八进制' , 0o176 )
print ( '十六进' , 0x1EAF )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
006 浮点类型
a = 3.14159
print ( a, type ( a) )
print ( 1.1 + 2.2 )
print ( 1.1 + 2.1 )
from decimal import Decimal
print ( Decimal( '1.1' ) + Decimal( '2.2' ) )
007 布尔类型
print ( True + 1 )
print ( False + 1 )
f1 = True
f2 = False
print ( f1, type ( f1) )
print ( f2, type ( f2) )
008 字符串类型
str1 = '人生苦短,我用Python'
str2 = "人生苦短,我用Python"
str3 = "人生苦短,我用Python"
str4 = '''人生苦短,
我用Python'''
print ( str1, type ( str1) )
print ( str2, type ( str2) )
print ( str3, type ( str3) )
print ( str4, type ( str4) )
009 数据类型的转换
name = "张三"
age = 20
print ( type ( name) , type ( age) )
print ( '我叫' + name + ',今年' + str ( age) + '岁' )
print ( "------ str()将其它类型转成str类型 ------" )
a = 10
b = 198.8
c = False
print ( type ( a) , type ( b) , type ( c) )
print ( str ( a) , str ( b) , str ( c) , type ( str ( a) ) , type ( str ( b) ) , type ( str ( c) ) )
print ( "---- int()将其它的类型转int类型 -----" )
s1 = '128'
f1 = 98.7
s2 = '76.77'
ff = True
s3 = 'hello'
print ( type ( s1) , type ( f1) , type ( s2) , type ( ff) , type ( s3) )
print ( int ( s1) , type ( int ( s1) ) )
print ( int ( f1) , type ( int ( f1) ) )
print ( int ( ff) , type ( int ( ff) ) )
print ( "---------- f1oat()函数,将其它数据类型转成f1oat类型 -----------" )
s1 = '128.98'
s2 = '76'
ff = True
s3 = 'hello'
i = 98
print ( type ( s1) , type ( s2) , type ( ff) , type ( s3) , type ( i) )
print ( float ( s1) , type ( float ( s1) ) )
print ( float ( s2) , type ( float ( s2) ) )
print ( float ( ff) , type ( float ( ff) ) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
010 注释
'''
我是多行注释
'''
str = '''我不是多行注释,
我是多行字符串'''
print ( str )
present = input ( '大圣想要什么礼物呢?' )
print ( present, type ( present) )
a = int ( input ( '请输入一个加数:' ) )
b = int ( input ( '请输入另-个加数:' ) )
print ( type ( a) , type ( b) )
print ( a + b)
012 算术运算符
print ( 1 + 1 )
print ( 1 - 1 )
print ( 2 * 4 )
print ( 1 / 2 )
print ( 11 / 2 )
print ( 11 // 2 )
print ( 11 % 2 )
print ( 2 ** 2 )
print ( 2 ** 3 )
print ( 9 // 4 )
print ( - 9 // - 4 )
print ( 9 // - 4 )
print ( - 9 // 4 )
print ( 9 % - 4 )
print ( - 9 % 4 )
013 赋值运算符
i = 3 + 4
print ( i)
a = b = c = 20
print ( a, id ( a) )
print ( b, id ( b) )
print ( c, id ( c) )
print ( '------------- 支持参数赋值 -------------' )
a = 20
a += 30
print ( a)
a -= 10
print ( a)
a *= 2
print ( a)
a /= 3
print ( a)
a //= 2
print ( a)
a %= 3
print ( a)
print ( '------------- 解包赋值 -------------' )
a, b, c = 20 , 30 , 40
print ( a, b, c)
print ( '---------- 交换两个变量的值 -----------' )
a, b = 10 , 20
print ( '交换之前:' , a, b)
a, b = b, a
print ( '交换之后:' , a, b)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
014 比较运算符
a, b = 10 , 20
print ( 'a>b吗?' , a > b)
print ( 'a, a < b)
print ( 'a<=b吗?' , a <= b)
print ( 'a>=b吗?' , a >= b)
print ( 'a==b吗?' , a == b)
print ( 'a!=b吗?' , a != b)
'''
一个=称为赋值运算符,==称为比较运算符
一个变量由三部分组成,标识,类型,值
== 比较的是值还是标识呢?比较的是值
比较对象的标识使用 is
'''
a = 10
b = 10
print ( a == b)
print ( a is b)
list1 = [ 11 , 22 , 33 , 44 ]
list2 = [ 11 , 22 , 33 , 44 ]
print ( list1 == list2)
print ( list1 is list2)
print ( id ( list1) )
print ( id ( list2) )
print ( a is not b)
print ( list1 is not list2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
015 布尔运算符
a, b = 1 , 2
print ( "--- and 并且 ---" )
print ( a == 1 and b == 2 )
print ( a == 1 and b < 2 )
print ( a != 1 and b == 2 )
print ( a != 1 and b != 2 )
print ( "--- or 或者 ---" )
print ( a == 1 or b == 2 )
print ( a == 1 or b < 2 )
print ( a != 1 or b == 2 )
print ( a != 1 or b != 2 )
print ( "--- not 对bool类型取反 ---" )
f = True
f2 = False
print ( not f)
print ( not f2)
print ( "--- in 与 not in ---" )
s = 'helloworld'
print ( 'w' in s)
print ( 'k' in s)
print ( 'w' not in s)
print ( 'k' not in s)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
016 位运算符
print ( 4 & 8 )
print ( 4 | 8 )
print ( 4 << 1 )
print ( 4 << 2 )
print ( 4 >> 1 )
print ( 4 >> 2 )
017 对象的布尔值
print ( bool ( False ) )
print ( bool ( 0 ) )
print ( bool ( 0.0 ) )
print ( bool ( None ) )
print ( bool ( '' ) )
print ( bool ( "" ) )
print ( bool ( [ ] ) )
print ( bool ( list ( ) ) )
print ( bool ( ) )
print ( bool ( tuple ( ) ) )
print ( bool ( { } ) )
print ( bool ( dict ( ( ) ) ) )
print ( bool ( set ( ) ) )
print ( '----- 以上对象的布尔值为False -----' )
print ( '----- 其它对象的布尔值均为True -----' )
print ( bool ( 18 ) )
print ( bool ( True ) )
print ( bool ( 'helloworld' ) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
018 选择结构
a = int ( input ( "请输入一个数字:" ) )
if a < 0 :
print ( "a是负数" )
elif a == 0 :
print ( "a为0" )
else :
print ( "a是正数" )
019 条件表达式
numa = int ( input ( '请输入第一个整数' ) )
numb = int ( input ( '请输入第二个整数' ) )
print ( str ( numa) + '大于等于' + str ( numb) if numa >= numb else str ( numa) + '小于' + str ( numb) )
020 pass语句
a = 10
if a != 10 :
pass
for i in [ 1 , 2 , 3 ] :
pass
def add ( ) :
pass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
021 range函数
r = range ( 10 )
print ( r)
print ( list ( r) )
r = range ( 1 , 10 )
print ( list ( r) )
r = range ( 1 , 10 , 2 )
print ( list ( r) )
print ( 10 in r)
022 循环结构
a = 0
s = 0
while a < 5 :
s += a
a += 1
print ( '和为' , s)
for item in 'Python' :
print ( item)
for i in range ( 10 ) :
print ( i)
for _ in range ( 5 ) :
print ( '人生苦短,我用Python' )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
023 流程控制语句
for item in range ( 3 ) :
pwd = input ( '请输入密码:' )
if pwd == '666' :
print ( '密码正确' )
break
else :
print ( '密码不正确' )
for item in range ( 1 , 51 ) :
if item % 5 != 0 :
continue
print ( item)
024 for-else和while-else
for item in range ( 3 ) :
pwd = input ( '请输入密码:' )
if pwd == '666' :
print ( '密码正确' )
break
else :
print ( '密码不正确' )
else :
print ( "对不起,三次输错密码,程序退出" )
i = 0
while i < 3 :
pwd = input ( '请输入密码:' )
if pwd == '666' :
print ( '密码正确' )
break
else :
print ( '密码不正确' )
i += 1
else :
print ( "对不起,三次输错密码,程序退出" )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
025 list列表
lst = [ 'hello' , 'world' , 98 ]
print ( lst)
lst2 = list ( [ 'hello' , 'wor1d' , 98 ] )
print ( lst2)
lst = [ 'hello' , 'world' , 98 , 'hello' ]
print ( lst. index( 'hello' ) )
print ( lst. index( 'hello' , 1 , 4 ) )
lst = [ 'he11o' , 'wor1d' , 98 , 'he11o' , 'wor1d' , 234 ]
print ( lst[ 2 ] )
print ( lst[ - 3 ] )
lst = [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ]
print ( lst[ 1 : 6 : 1 ] )
print ( '原列表id:' , id ( lst) )
lst2 = lst[ 1 : 6 : 1 ]
print ( '切的片段id:' , id ( lst2) )
print ( lst[ 1 : 6 : 2 ] )
print ( lst[ 1 : 6 : ] )
print ( lst[ : 6 : 2 ] )
print ( lst[ 1 : : 2 ] )
print ( "步长为负数的情况" )
print ( "原列表:" , lst)
print ( "负数步长截取的列表:" , lst[ : : - 1 ] )
print ( lst[ 7 : : - 1 ] )
print ( lst[ 6 : 0 : - 2 ] )
lst = [ 10 , 20 , 'python' ]
print ( 'python' in lst)
print ( 10 not in lst)
for item in lst:
print ( item)
'''
10
20
python
'''
lst = [ 10 , 20 , 30 ]
print ( '添加元素之前' , lst, id ( lst) )
lst. append( 100 )
print ( '添加元素之后' , lst, id ( lst) )
lst2 = [ 1 , 2 , 3 ]
lst. extend( lst2)
print ( lst)
lst. insert( 1 , 90 )
print ( lst)
lst3 = [ True , False , 'hello' ]
lst[ 1 : ] = lst3
print ( lst)
lst = [ 10 , 20 , 30 , 40 , 50 , 60 , 30 ]
lst. remove( 30 )
print ( lst)
lst. pop( 1 )
print ( lst)
lst. pop( )
print ( lst)
print ( '----- 切片操作 删除至少一个元素,将产生一个新的列表对象 ----' )
new_list = lst[ 1 : 3 ]
print ( '原列表' , lst)
print ( '切片后的列表' , new_list)
lst[ 1 : 3 ] = [ ]
print ( lst)
lst. clear( )
print ( lst)
del lst
lst = [ 10 , 20 , 30 , 40 ]
lst[ 2 ] = 100
print ( lst)
lst[ 1 : 3 ] = [ 300 , 400 , 500 , 600 ]
print ( lst)
lst = [ 20 , 40 , 10 , 98 , 54 ]
print ( '排序前的列表' , lst, id ( lst) )
lst. sort( )
print ( '排序后的列表' , lst, id ( lst) )
lst. sort( reverse= True )
print ( lst)
lst. sort( reverse= False )
print ( lst)
print ( '--------- 使用内置函数sorted()对列表进行排序,将产生一个新的列表对象 --------------' )
lst = [ 20 , 40 , 10 , 98 , 54 ]
print ( '原列表' , lst)
new_list = sorted ( lst)
print ( lst, id ( lst) )
print ( new_list, id ( new_list) )
lst = [ i * i for i in range ( 10 ) ]
print ( lst)
lst = [ i * 2 for i in range ( 1 , 6 ) ]
print ( lst)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
026 dict字典
scores = { '张三' : 100 , '李四' : 98 , '王五' : 45 }
print ( scores)
print ( type ( scores) )
student = dict ( name= 'jack' , age= 20 )
print ( student)
d = { }
print ( d)
scores = { '张三' : 100 , '李四' : 98 , '王五' : 45 }
print ( scores[ '张三' ] )
print ( scores. get( '张三' ) )
print ( scores. get( '陈六' ) )
print ( scores. get( '麻七' , 99 ) )
scores = { '张三' : 100 , '李四' : 98 , '王五' : 45 }
print ( '张三' in scores)
print ( '张三' not in scores)
del scores[ '张三' ]
print ( scores)
scores. clear( )
print ( scores)
scores[ '陈六' ] = 98
print ( scores)
scores[ '陈六' ] = 100
print ( scores)
scores = { '张三' : 100 , '李四' : 98 , '王五' : 45 }
keys = scores. keys( )
print ( keys, type ( keys) )
print ( list ( keys) )
values = scores. values( )
print ( values, type ( values) )
print ( list ( values) )
items = scores. items( )
print ( items, type ( items) )
print ( list ( items) )
for key in scores:
print ( key, scores[ key] , scores. get( key) )
'''
张三 100 100
李四 98 98
王五 45 45
'''
items = [ 'Fruits' , 'Books' , 'Others' ]
prices = [ 96 , 78 , 85 ]
d = { item: price for item, price in zip ( items, prices) }
print ( d)
d = { item. upper( ) : price for item, price in zip ( items, prices) }
print ( d)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
027 tuple元组
t = ( 'Python' , 'world' , 98 )
print ( t)
print ( type ( t) )
t = 'Python' , 'world' , 98
print ( t)
print ( type ( t) )
t = ( 10 , )
t1 = tuple ( ( 'Python' , 'world' , 98 ) )
print ( t1)
print ( type ( t1) )
t = ( )
t = tuple ( )
t = ( 10 , [ 20 , 30 ] , 9 )
print ( t)
print ( type ( t) )
print ( t[ 0 ] , type ( t[ 0 ] ) , id ( t[ 0 ] ) )
print ( t[ 1 ] , type ( t[ 1 ] ) , id ( t[ 1 ] ) )
print ( t[ 2 ] , type ( t[ 2 ] ) , id ( t[ 2 ] ) )
print ( id ( 100 ) )
print ( t)
t[ 1 ] . append( 111 )
print ( t)
for item in t:
print ( item)
'''
10
[20, 30, 111]
9
'''
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
028 set集合
s = { 2 , 3 , 4 , 5 , 5 , 6 , 7 , 7 }
print ( s)
s1 = set ( range ( 6 ) )
print ( s1, type ( s1) )
s2 = set ( [ 1 , 2 , 4 , 5 , 5 , 5 , 6 , 61 ] )
print ( s2, type ( s2) )
s3 = set ( ( 1 , 2 , 4 , 4 , 5 , 65 ) )
print ( s3, type ( s3) )
s4 = set ( 'python' )
print ( s4, type ( s4) )
s5 = set ( )
s = { 10 , 20 , 30 , 405 , 60 }
print ( 10 in s)
print ( 100 in s)
print ( 10 not in s)
print ( 100 not in s)
s. add( 80 )
print ( s)
s. update( { 200 , 400 , 300 } )
print ( s)
s. update( [ 100 , 99 , 8 ] )
s. update( ( 78 , 64 , 56 ) )
print ( s)
s. remove( 100 )
print ( s)
s. discard( 500 )
s. discard( 300 )
print ( s)
s. pop( )
s. pop( )
print ( s)
s. clear( )
print ( s)
s1 = { 1 , 2 , 3 , 4 }
s2 = { 4 , 3 , 2 , 1 }
print ( s1 == s2, s1 != s2)
a = { 1 , 2 }
b = { 4 , 3 , 2 , 1 }
print ( a. issubset( b) )
a = { 4 , 3 , 2 , 1 }
b = { 4 , 3 }
print ( a. issuperset( b) )
a = { 1 , 2 , 3 }
b = { 3 , 6 , 8 }
print ( a. isdisjoint( b) )
s1 = { 10 , 20 , 30 , 40 }
s2 = { 20 , 30 , 40 , 50 , 60 }
print ( s1. intersection( s2) )
print ( s1 & s2)
print ( s1. union( s2) )
print ( s1 | s2)
print ( s1. difference( s2) )
print ( s1 - s2)
print ( s1. symmetric_difference( s2) )
print ( s1 ^ s2)
s = { i * i for i in range ( 10 ) }
print ( s, type ( s) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
029 str字符串常用操作
s = 'hello,hello'
print ( s. index( 'lo' ) )
print ( s. find( 'lo' ) )
print ( s. rindex( 'lo' ) )
print ( s. rfind( 'lo' ) )
print ( s. find( 'k' ) )
print ( s. rfind( 'k' ) )
s = 'hello,python'
a = s. upper( )
print ( a, id ( a) )
print ( s, id ( s) )
print ( s. lower( ) , id ( s. lower( ) ) )
print ( s, id ( s. lower( ) ) )
s = 'hello,Python'
print ( s. center( 20 , '*' ) )
print ( s. ljust( 20 , '*' ) )
print ( s. rjust( 20 , '*' ) )
print ( s. zfill( 20 ) )
s = 'hello world Python'
lst = s. split( )
print ( lst)
s1 = 'hello|world|Python'
print ( s1. split( sep= '|' ) )
print ( s1. split( sep= '|' , maxsplit= 1 ) )
print ( s. rsplit( ) )
print ( s1. rsplit( '|' ) )
print ( s1. rsplit( sep= '|' , maxsplit= 1 ) )
print ( "hello" . isidentifier( ) )
print ( " " . isspace( ) )
print ( "add" . isalpha( ) )
print ( "12" . isdecimal( ) )
print ( "588585" . isnumeric( ) )
print ( "hello666" . isalnum( ) )
s = 'hello,Python'
print ( s. replace( 'Python' , 'Java' ) )
s1 = 'hello,Python,Python,Python'
print ( s1. replace( 'Python' , 'Java' , 2 ) )
lst = [ 'hello' , 'java' , 'Python' ]
print ( '|' . join( lst) )
print ( '' . join( lst) )
t = ( 'hello' , 'Java' , 'Python' )
print ( '' . join( t) )
print ( 'apple' > 'app' )
print ( 'apple' > 'banana' )
print ( ord ( 'a' ) , ord ( 'b' ) )
print ( ord ( '杨' ) )
print ( chr ( 97 ) , chr ( 98 ) )
print ( chr ( 26472 ) )
'''
==与is的区别
== 比较的是value
is 比较的是id是否相等’
'''
a = b = 'Python'
c = 'Python'
print ( a == b)
print ( b == c)
print ( a is b)
print ( a is c)
print ( id ( a) )
print ( id ( b) )
print ( id ( c) )
s = 'hello,Python'
s1 = s[ : 5 ]
s2 = s[ 6 : ]
s3 = '!'
newstr = s1 + s3 + s2
print ( s1)
print ( s2)
print ( newstr)
print ( s[ 1 : 5 : 1 ] )
print ( s[ : : 2 ] )
print ( s[ : : - 1 ] )
name = '张三'
age = 20
print ( '我叫%s,今年%d岁' % ( name, age) )
print ( '我叫{0},今年{1}岁' . format ( name, age) )
print ( f'我叫 { name} ,今年 { age} 岁' )
print ( '{0:.3}' . format ( 3.1415926 ) )
print ( '{:.3f}' . format ( 3.1415926 ) )
print ( '{:10.3f}' . format ( 3.1415926 ) )
s = '天涯共此时'
print ( s. encode( encoding= 'GBK' ) )
print ( s. encode( encoding= 'UTF-8' ) )
byte = s. encode( encoding= 'GBK' )
print ( byte. decode( encoding= 'GBK' ) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
030 def函数
'''
def 函数名(输入参数):
函数体
return xxx
'''
def add ( a, b) :
return a + b
print ( add( 1 , 2 ) )
print ( add( b= 2 , a= 1 ) )
'''
在函数调用过程中,进行参数的传递
如果是不可变对象,在函数体的修改不会影响实参的值arg1的修改为100,不会影响n1的值
如果是可变对象,在函数体的的修改会影响到实参的值arg2的修改,append(l0),会影响到n2的值
'''
def fun1 ( ) :
pass
def fun2 ( ) :
return 1
def fun3 ( ) :
return 1 , 2
def fun4 ( a= 10 ) :
print ( a)
def fun5 ( * args) :
print ( args)
fun5( 1 , 2 , 3 )
def fun6 ( ** args) :
print ( args)
fun6( a= 1 , b= 2 , c= 3 )
'''
def fun (*args,*a):
pass
以上代码,程序会报错,个数可变的位置参数,只能是1个
def fun (**args,**args):
pass
以上代码,程序会报错,个数可变的关键字参数,只能是1个
def fun(**args1, *args):
pass
以上代码,程序会报错,只能是这样的形式:fun(*args1, **args) 即位置参数必须在关键字形参之前
'''
def fun7 ( * args1, ** args) :
pass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83