python学习笔记001-python中变量数据类型和分支结构
source link: http://www.mrliangqi.com/1706.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
python学习笔记001-python中变量数据类型和分支结构
Python实战 2022-04-02 0 5
主要从变量,数据类型,分支结构与循环结构,函数以及类与对象:
vscode下载:
https://mrliangqi.oss-cn-beijing.aliyuncs.com/python/VSCode-darwin-universal.zip
1.数字计算
a4=10/8
a5=a4*2
a6=a5/3
print (a4,type(a4),a5,type(a5),a6,type(a6))
2.与或和
stu=93
a7=stu>90
a8=stu<60 a9=a7 and a8 a10= a7 or a8 print (a7,type(a7),a8,type(a8),a9,type(a9),a10,type(a10) ) 3.字符串\n换行,一个字符 a1=”hi, \n503″ a2=”im \nhere” a3=a1+”,”+a2 print (a1,type(a1)) print(a3,type(a3)) 4.列表,可以存储多个字符 创建使用中括号,中间可以一个或者多个值,逗号分开 获取长度,可以用过len函数计算 获取元素,痛殴变了X 的形式访问列表中第X个值 增删元素,创建之后,可以用append添加,remove删除函数元素 ![请输入图片描述][3] 5.if 语句格式: 案例: a=90 if a>80:
print(“非常好”)
print(“code finished”)
6.if-else语句:
案例:
a=70
if a>80:
print(“非常好”)
else:
print(“需要努力哈!”)
print(“code finished”)
7.if-elif-else语句:
案例:
a=79
if a>80:
print(“非常好!”)
elif a>60:
print(“及格了!”)
else:
print(“再接再厉!”)
print(“code finished”)
8.for 语句 实现循环方式之一
i,循环变量 1,开始值 10,结束值 1,步长
for i in range (1,10,1):
print(i)
案例:
su=0
for i in range(1,101):
su=su+i
print(su)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK