python简说(一)if,for等
一.python简说
python可以用于自动化测试、web开发、数据分析、AI python、自动化运维,第三方模块最多的一个语言。
编译型语言
c、c++
要运行,先要编译,编译成二进制的。
解释型语言
python、php、java、ruby、js
什么时候运行,什么时候编译
二.基本语法
1.变量,存东西的。
变量名可以是中文,好奇葩,不要这样写,谁写谁sb。
name = '小黑' "单词" 字符串 str,单引双引没区别
age = 18 int 整数
score = 98.5 float 小数
2.引号的用处:
words=" let's go"
words2= '他长得 "真帅" 啊'
words3=''' '他长得 "真帅" 啊' '''
3.输入输出:
使用input接收到的全都是字符串
name = input('请输入你的名字:')
aw_input('') #python2
print('你输入的是',name)
4.条件判断:
1)if else > < >= <= != ==
if age >= 18:
print('你成年了')
else:
print('未成年!')
2)if elif else
score = input("请输入你的分数:")
score = int(score) 强转为int类型
print( type(score) ) 输出看是什么类型
if score>=90:
print('优秀!')
elif score>=80 and score<90 :
print('良好')
elif score>=60 and score<80:
print('及格')
else
print('不及格')
5.循环
while
count =0
while count<10:
if count%2 !=0:
print(count)
count=count+1
for循环
for i in range(1,10): 循环1到9
print('i的值是',i)
break 在循环里面只要遇到break立即结束循环
continue 在循环里面遇到continue,结束本次循环,进行下一次循环
while和for可以对应else
for循环可以嵌套
6.参数化
1)word='欢迎'+ username +'登录!
2)word2 = '欢迎 %s 登录。。今天的日期是 %s '%(username,today)
3)word3='你得年龄是 %03d 你的分数是%.2f '%(18,92.3)
word3='你得年龄是 %s 你的分数是%s '%(18,92.3)
7.结束符
print('abc',end=' ')
end里面是什么,就是什么格式
print()默认end=/n 换行k