001基础学习
#00
在python里面没有常量,只有变量
#01
删除变量:del 变量名
#02
coding:utf-8 //设置utf-8编码
#03
单行注释:#
多行注释:三个任意符号,一般用'''
#04
table键和四个空格不相等,缩进要保持一致
我的IDLE中默认按tab键就是四个空格
多行代码:尾部+ '\' ,或者用多行注释的方法,多行注释赋值给一个是多行字符串
#05运算符
//,地板除,相当于c语言的int除法
2**10,2的10次方
#06简单作业所得
python读取写入文件,简单使用
if os.path.exists(filename): #判断是否有这个文件
fp = open( filename )
times = int(fp.read())
fp.close()
fp.write(str(times))
#07短路
and or短路
#08 for while循环
for while执行到尾,没被打断,则执行else的内容
#09
print不换行,print("",end=""),end原来是默认换行=“\n”,改了就行了。
#10格式化输出
#判断是不是数字,isdigit()方法
# exit("你必须输入数字")
#查看数据类型 type(变量名)
#for循环
str.format("三角形的三边分别为:a={0:2},b={1:2},c={2:2}",a,b,c)
#三目运算符
year=input("输入年份:")
year=int(year) if year.isdigit() else exit("输入整数")
#类似传递值和传址
a=b, a和b的地址是相同的;
只是想拷贝,那么就得用 a=b[:]。