def printInfo():
print('--------------------------------')
print('生命苦短男图,我用python')
print('--------------------------------')
printInfo()
def add2Num(a,b):
c=a+b
print(c)
add2Num(11,33)
def nameinfo(name,age=36):
print("Name",name)
print("Age",age)
nameinfo(name="kiki")
nameinfo("kikii",age=29)
def test(a,b,*args,**kwargs):
print(a)
print(b)
print(args)
print(kwargs)
test(11,222)
#空元組、空字典
test(11,22,33,44,m="sunqicheng",n="nan")
def getTemprature():
return 24
temperature=getTemprature()
print('當前的溫度為:',temperature)
def sum(n):
sum=0
? ? i=1
? ? #再記不住磺送,就是這種累加和的车份,要用三個變量啊谋减,一個sum 一個n也就是總數(shù)一個也就是遞增的i
? ? while i<=n:
sum=sum+i
i+=1
? ? return sum
print(sum(10))
#Llocal函數(shù)內(nèi)的區(qū)域,包括局部變量和形參
#Enclosing 外面嵌套函數(shù)的區(qū)域扫沼,常見的是閉包函數(shù)外的函數(shù)
#Gglobal 全局作用域
#B內(nèi)建作用域
----------------------------------------------------------------------------------------------------
import random
#這下面都是浮點數(shù)出爹,也就是小數(shù)
print("random():",random.random())
print(random.uniform(1,10))
print(random.uniform(10,1))
#從這里開始是整數(shù)
print(random.randint(12,20))
print(random.randint(13,15))
print(random.randrange(10,100,5))
print(random.choice(['sunqicheng','is','handsome','boy','saynothing']))
print(random.choice(("tuple","list","dict","sequence")))
-----------------------------------------------------------------------------------------------------------
import random
p=['sunqicheng','is','handsome','boy','saynothing']
random.shuffle(p)
print(p)
#['boy', 'is', 'handsome', 'saynothing', 'sunqicheng']
import random
p=['sunqicheng','is','handsome','boy','saynothing']
slice=random.sample(p,3)
#random.shuffle(p)
print(slice)