面向对象

 1 global变量
 2 x=50
 3 def func():
 4     global x
 5     print('x is ',x)
 6     x=2
 7     print('changed global x to ',x)
 8 func()
 9 print('value of x is',x)
10 
11 def say(message,times=1):
12     print(message*times)
13 say('hello')
14 say('world',5)
15 hello
16 worldworldworldworldworld
17 函数参数列表中的默认参数必须位于括号的末尾
18 
19 关键字参数
20 dint('a is ',a,'and b is',b,'and c is ',c)
21 func(3,7)
22 func(25,c=24)
23 func(c=50,a=100)
24 
25 def total(a=5,*numbers,**phonebook):
26     print('a',a)
27     for i in numbers:
28         print('i', i)
29     for first_part,second_part in phonebook.items():
30         print(first_part, second_part)
31 print(total(10,1,2,3,jack=1123,john=2231,Inge=1560))
32 
33 每一个函数都在结尾默认地加上了一句,return none
34 
35 模块类似导包
36 import math
37 print("Squr is",math.sqrt(16))
38 
39 class Person:
40     def __init__(self,name)://类似构造函数的功能
41         self.name=name
42     def say_hi(self):
43         print('hello',self.name)
44 p=Person('ghjghj')
45 p.say_hi()

 

转载于:https://www.cnblogs.com/L-Pxiaotiancai/p/8397536.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值