主要是是在学习过程中的一些记录笔记
有一部分是莫凡视频教程里的代码,正则部分是别的视频里的
# print 函数
print("hello world")
print('hello world'+str(4))#转换为字符串
print("int(2**2)")
print(2**2) # 2的2次方
print(2+2)# 2+2
print(int('2')+2)# 字符串转换为整型
# 运算符
print(8%2)# 取余数
print(8//2)# 取整 4 有多少个2
# 自变量
apple_one=1+20
print(apple_one)#
#定义多个变量
a,b,c=1,2,3
print(a,b,c)
# while 循环
condition=1
while condition<10:
print(condition)
condition=condition+1
# for 循环
example_list=[1,2,3,4,5,6,7,8,900]
for i in example_list:
print(i)# 输出 数组里的每一个数
for i in range(1,17,3):# 不包括 17
print(i)
#if else
x,y,z=1,2,3
if x>y:
print("x>y")
elif x>1: #只要有一个成立,后面的就不会执行
print("")
else:
print("x<y")
#def 定义函数
def function(a=1,b=1,c=1):# 定义这个而函数,当调用时候才会执行;可以给定默认值
c=a+b
print("the c is=",c,
"the b is=",b,
"the a is=",a)
function(2,3,4)
# 全局变量 局部变量
APPLE=100#全局变量一般都大写,在函数外面
a1=None
def fun():
global a1# 定义全局变量
a1=10
print(a1)
return a1+100
#fun()#执行函数
print(fun())#执行函数,并输出返回值
# 安装模块
# pip3 install
# pip3 uninstall numpy
# pip3 install numpy-1.9.2
#pip3 install -U numpy
# 文件读写
text=" this is .\n test file .\n this is next line .\n"#
print(text)
my_file=open("my_file.txt","w")# “w”写 “r”读
my_file.write(text)
my_file.close()
#在文件后追加文字
text="wo\na\n"
my_file=open("my_file.txt","a")
my_file.write(text)
my_file.close()
file=open("my_file.txt","r")# 打开是open
# content=file.read()
# print(content)
content2=file.readlines()
print(content2)
# 定义类
class Calculator:
name="Good Calculator" # 属性
price="18"#功能
def add(self,x,y):#self 说明在类是默认参数,会被传下去
result=x+y
print(self.name)
print(result)
ca=Calculator()
print(ca.name)
print(ca.price)#外部调用 定义的类名,内部用的话用self
ca.add(5,6)
#init功能 初始
class Calculator:
# name="Good Calculator" # 属性
# price="18"#功能
def __init__(self,name,price,hight,width,weight):
self.name=name # 我感觉就是默认参数
self.price=18
self.h=hight
self.wi=width
self.wi=weight
def add(self,x,y):#self 说明在类是默认参数,会被传下去
result=x+y
print(self.name)
print(result)
aa=Calculator("BAD",12,30,15,10)
print(aa.name)
print(aa.wi)#外部调用 定义的类名,内部用的话用self
#input
# a_input=input("爱不爱我:")
# print("输入的是",a_input)
# if a_input=="爱":
# print("哈哈哈")
# else:
# print("滚吧")
# 元组和列表
#tuple lise
a_tuple=(12,12,13,14)#我觉得元组就是不可变的列表
a_list=[12,13,14,15]
print(a_list)
for content in a_list:
print(content)