码迷,mamicode.com
首页 > 编程语言 > 详细

python学习

时间:2017-11-18 15:59:56      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:maximum   message   ==   turn   doc   module   imp   变量   bsp   

1.全局变量写法

def func():
global x
print (‘x is‘,x)
x=2
print (‘Changed local x to‘, x)
x= 50
func()
print (‘x is still‘ ,x )

2.改变形参和不改变形参设默认值用法

def say(message,times =3 ):
print (message * times )
say (‘Hello‘)
say (‘World‘,5)

3给关键参数赋值即可

def func(a,b=5,c =10 ):
print (‘a is‘ , a , ‘and b is ‘ , b , ‘and c is ‘, c )
func (3,7)
func (25,c =24)
func (c = 50 , a= 100)

4.return 用法跳出函数返回值

def maximum (x,y):
if x>y :
return x
print (x,‘>‘,y,‘is true ‘)
else:
return y
print (maximum (3,2))

5.docstring 用法

def printMax(x,y):
‘‘‘Prints the maximum of two numbers.

The two values must be integers. ‘‘‘
x= int (x)
y= int (y)

if x>y:
print (x,‘is maximum‘)
else :
print (y,‘is maximum‘)
printMax(3,5)
print (printMax.__doc__)

6. sys模块使用


import sys

print(‘ The command line arguments are:‘)
for i in sys .argv:
print (i)

print (‘\n\n The PYTHONPATH is ‘ ,sys.path, ‘\n‘)

7.name的用法


if __name__ == ‘ __main__‘:
print (‘This program is being run by itself ‘)
else :
print (‘I am being imported from another module‘)

 

python学习

标签:maximum   message   ==   turn   doc   module   imp   变量   bsp   

原文地址:http://www.cnblogs.com/dadaozhijian22/p/7856784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!