- 标准数据类型
b = 5.5
print(type(b))
------
<class 'float'>
类型是属于对象的,变量仅仅是对对象的引用
number,string,list,tuple,set,dictionary
s = 'ab' ls = [1, 'd', True] tuple = (1,'d') set = {..} dict = {'a':1} #创建字典 dict['b'] = 2 #向字典添加元素
- 成员运算符
[not] in :return True or False
for <var> in <seqyence>: #常与range()搭配
<statement>
else:
<statement>
- 身份运算符
[not] is
- function
def max(a, b):
if a>b:
return a
else:
return b
- Module
#support.py
def print_func(par):
print('hello:',par)
return
#test.py
import support
support.print_func('f')
---------------
hell0:f
__name__属性:使模块仅在该模块自身运行时被执行
if __name__ == '__main__': print('程序自身运行') else: print('程序被调用')
- class
class complex:
def __init__(self, a, b): # __init__方法实例化,self代表类的实例
self.x = a # 类的方法的定义须有参数self,且为第一个
self.y = b
def m(self,c):
return (a*a + b*b)^(c/2)
z = complex(3,4)
print(z.x, z.y)
print(z.m(2))
---------------
3,4
5