# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:19
# @Author : 李新宇
# @FileName: demo1.py
# @Software: PyCharm
def fun():
pass
def fun2():
pass
class Student:
native_place='吉林' #类属性
def eat(self,name,age):
self.name=name
self.age=age
@staticmethod
def sm():
pass
@classmethod
def cm(cls):
pass
a=1
b=2
c=a+b
print(c)
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:27
# @Author : 李新宇
# @FileName: demo2.py
# @Software: PyCharm
import math
print(id(math))
print(type(math))
print(math)
print(math.pi)
print('----------------------------')
print(dir(math))
print(math.pow(2,3))
print(math.ceil(9.001))
print(math.floor(9.001))
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:32
# @Author : 李新宇
# @FileName: demo3.py
# @Software: PyCharm
from math import pi
import math
print(pi)
print(pow(2,3)) #8 非math中的pow,若不引入math,
print(math.pow(2,3)) #8.0
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:37
# @Author : 李新宇
# @FileName: calc.py
# @Software: PyCharm
def add(a,b):
return a+b
def div(a,b):
return a/b
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:39
# @Author : 李新宇
# @FileName: demo5.py
# @Software: PyCharm
'''在demo5中导入calc自定义模块使用'''
import calc
print(calc.add(10,20))
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:51
# @Author : 李新宇
# @FileName: demo6.py
# @Software: PyCharm
from calc import add
print(add(1,2))
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:52
# @Author : 李新宇
# @FileName: calc2.py
# @Software: PyCharm
def add(a,b):
return a+b
if __name__ == '__main__':
print(add(10,20)) #只有当点击运行calc2时,才会执行运算
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 18:53
# @Author : 李新宇
# @FileName: demo8.py
# @Software: PyCharm
import calc2
print(calc2.add(100,200))
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 19:10
# @Author : 李新宇
# @FileName: module_A.py
# @Software: PyCharm
a=10
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 19:11
# @Author : 李新宇
# @FileName: module_B.py
# @Software: PyCharm
b=100
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 19:11
# @Author : 李新宇
# @FileName: domo9.py
# @Software: PyCharm
#在demo9的模块中导入package的包
import package1.module_A as ma #ma,起的模块的别名
#print(package1.module_A.a)
print(ma.a)
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 19:15
# @Author : 李新宇
# @FileName: demo10.py
# @Software: PyCharm
#在导入带有包的模块时的注意事项
import package1
import calc
#使用import方式进行导入时,只能跟包名或模块名
from package1 import module_A
from package1.module_A import a
#使用from。。import可以导入包、模块、函数、变量
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 19:19
# @Author : 李新宇
# @FileName: demo11.py
# @Software: PyCharm
import sys
import time
print(sys.getsizeof(24))
print(sys.getsizeof(45))
print(sys.getsizeof(True))
print(sys.getsizeof(False))
print(time.time())
print(time.localtime(time.time()))
# -*- coding: utf-8 -*-
# @Time : 2021/10/3 19:29
# @Author : 李新宇
# @FileName: demo12.py
# @Software: PyCharm
#模块安装省略,具体模块具体百度
#依次点击Settings👉Project:test👉Project Interpreter
#点击右上角的➕,进去输入需要的模块,然后点击左下角 ,等待安装完成即可。