资源描述
Python基础:常用知识点汇总01下载与安装
Python 下载地址:Python 文档下载地址:
PyCharm下载地址: s:〃
官方宣布,2020年1月1日,停止Python2的更新,建议下载 Python3o下载好以后,要进行环境变量配置,以Windows为例, 在命令提示框中(cmd)输入:
path=%path%;C:\Python按下Enter,即可在环境变量中添加Python目录。
PyCharm是由JetBrains打造的一款Python IDE,具有调试、 语法高亮、Project管理等功能,当然你也可以选择其他IDE。
02你的第一个程序翻开PyCharm,新建一个py文件,输入:
print("Hello」 World!”)右键,运行,结果如下:
6.第二个while循环
运行结果:
运行结果:
12
38. continue
print(“-”*30)#结束本次循环(第5次)
运行结果:
12
36
78
910
9.分别用for循环和while循环实现九九乘法表
for i in range(lJ10): #用for循环写九九乘法表for j in range(l)i+1):
print (”%d*%d=%d”%(i, j, i* j), end=' \t1)
pr
i = 1 #用while循环写九九乘法表
while i < 10:
运行结果:
5*1=5
5*1=5
5*2=10 5*3=15 5*4=20 5*5=256*1=66*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=77*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7= 498*1=88*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7= 56 8*8=64
9*1=99*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7= 63 9*8=72 9*9=81
Hello, World!
03注释.单行注释
Sprint("hello world").多行注释
这是第一行注释这是第二行注释
被注释的代码将不会运行。
04输出与输入.标准化输出
print("标准化输出字符串”)
运行结果:
标准化输出字符串.格式化输出
name = "菜 J 学 Python”print("我的名字是:%s,我的国籍是:%s"%(nameJcountry)) #%s
运行结果:
我的名字是:菜:]学Python,我的国籍是:China.其他输出
print ("www""baidu''^ "com''^ sep=".")printCworld11 jend=,,\t11) #空格不换行|
运行结果:
aaa bbb ccchelloworld python end
1 .输入print(“您刚刚输入的密码是:;password)
右键运行,输入“菜J学Python”后按下Enter键。
运行结果:
您刚刚输入的密码是:菜J学Python05条件控制
建议使用tab键和shift+tab键调节缩进,让相同代码块对齐。
1. if-elseprint("False")
运行结果:
2. if-elif-elseif score > 90 and score <= 100口
elif score > 80 and score <=elif score > 60 and score <= 8记
print("本次菜3考试等级为D")运行结果:
本次菜3考试等级为Dif-else 嵌套
danshen = 0 #1代表单身,0代表有力/女朋友1 if xingbie == 1 :
print(“男生”)
运行结果:
男生有妹子的男生
06循环语句1.第一个for循环
or i in range(5): #基本循环print(i)
运行结果:
0 I1 I
2 I3
2 .第二个for循环for i in range(0,10,3): #从o开始到10结束,步进值为3(每 次+3)
print(i)运行结果:
3I
6I
9.第三个for循环
name = "chengdu" #循环遍历所有字母print(x,end="\t”)
运行结果:
c h e n g d u.第四个for循环
a = [,,aa,,/,bb,,/,cc,,/,dd,,] #循环遍历列表(len(a)=4)for i in range(len(a)):
运行结果:
0 aa ■1 bb
2 cc 3 dd
运行结果:
当前是第1次执行循环当前是第2次执行循环
当前是第3次执行循环当前是第4次执行循环
当前是第5次执行循环i=4
展开阅读全文