今日所得
Python中注释的重要性
Python与用户相交互:
1.输入
2.输出
3.格式化输出
Python的基本数据类型:int,float,str,list,dict,bool
运算符
1.基本运算符
2.逻辑运算符
Python程序中的注解
注解是一个程序员对自己的代码所做出的解释,也是为了别人能够好好地理解和看懂自己写的程序
注解的几种使用方式
1.单行注解
cum = 0 count = 0 while count <100: # 使count在100里循环 count += 1 cum = count + cum # 让循环数字相加 print(cum)
2.多行注解
cum = 0 count = 0 while count <100: count += 1 cum = count + cum print(cum) """ 上述代码为1到100的数相加 其结果为5050 """
输入
1.在Python3版本中
input()统一为输入的所有数据都存成字符串类型
2.在Python2版本中
1.input()输入时要声明输入的是什么变量
2.raw_input()输入的数据会统一存为字符串类型
格式化输出
print(‘my name is %s my age is %s‘%(name,age)) print(‘my name is %s my age is %s‘%(age,name)) # 没有顺序 print(‘my name is %s my age is %s‘%(‘Abraham‘,[1,2,3,4,5])) # %d只能给数字占位 %s可以给任意数据类型占位
Python的基本数据类型
int:整数型
float:浮点型
str:字符串
list:列表
li=[ [‘asd‘,4454,[‘run‘,]], [‘hhh‘,3178,[‘fight‘,‘touch‘]] ] l1 = students_info[1] l2 = l1[2] res = l2[1] print(res) print(li[1][2][1])
dict:字典
dict = {‘Name‘: ‘Runoob‘, ‘Age‘: 7, ‘Class‘: ‘First‘} print ("dict[‘Name‘]: ", dict[‘Name‘]) print ("dict[‘Age‘]: ", dict[‘Age‘])
bool:布尔值
运算符
1.基本运算符:+(加),-(减),*(乘),/(除),//(取商),%(取余数),==(等于),<(小于),>(大于),!=(不等于),<=(小于等于),>=(大于等于)
2.逻辑运算符:and(与),or(或),not(非)
print( 1 > 0 and 3 > 4) # and两边必须同时成立 结果才成立 print( 1 > 0 or 1 > 0 and 3 > 4) # or只要有一边成立 立即成立 后面的无需再看 print(not 1 > 3) # 结果取反
数据类型
数据:衡量/记录事物的状态/特征
类型:不同的数据应该有不同的数据类型储存
个人所得:Python的程序代码运行途中,修改了数据需要重新运行一遍
用户输入的统一都是字符串
原文:https://www.cnblogs.com/AbrahamChen/p/11115526.html