基础

    技术2022-07-12  82

    一、编译型和解释型的区别 1、编译型:一次性将全部的代码编译成二进制文件。(c、c++) 优点:运行效率高 缺点:开发速度慢,不能跨平台 2、解释型:当程序运行时, 从上至下一行一行的解释成二进制。 优点:开发速度快,效率高,可以跨平台 缺点:运行效率低 二、python2x和python3x宏观上的区别 1、python2x源码,重复率高,不规范,而且python崇尚的是简优美清晰,所以创建python3,规范化。 2、在python2首行:#--encoding:utf-8--解决python2中文报错问题。 三、变量和常量 1、变量:由数字、字母、下划线任意组成,且不能以数字开头,具有可描述性,不能用python中的关键字,不能用中文,不能用拼音。 2、常量:约定俗成,不可更改,全部是大写字母。 四、注释(单行、多行) 1、单行注释:# 2、多行注释:’’’ ‘’’,""" “”" 五、用户交互input:数据类型全部是str 六、基础数据类型: 1、bool:Ture False 2、int:+ - * / % // ** 3、str:加引号的就是str +可以与数字* 七、流程控制语句if

    #情况一 if 条件: 结果 #情况二 if 条件: 结果 else: 结果 #情况三 if 条件: 结果 elif 条件: 结果 elif 条件: 结果 else: 结果 #情况四 if 条件: if 条件:结果 if 条件:...... else:结果

    八、如何终止while循环

    while 条件: 结果

    1、改变条件 2、break 3、continue:结束本次循环,继续下一次循环 九、作业 1、使用while循环输入1 2 3 4 5 6 空格 8 9 10

    count=0 while count<11: count+=1 if count==7: print(' ') else: print(count)

    2、使用while循环输入1 2 3 4 5 6 8 9 10

    #方法一: count=0 while count<11: count+=1 if count==7: continue print(count) #方法二: count=0 while count<11: count+=1 if count==7: pass#什么都不执行,跳过 else: print(count)

    3、输出1到100内的所有奇数

    #方法一: count=1 while count<101: print(count) count+=2 #方法二:先打印出1到100,再找规律 count=1 while count<101: if count%2==1: print(count) count+=1

    4、求1-2+3-4+5…99的所有数的和

    sum=0 count=1 while count<=100: if count%2==0: sum-=count else: sum+=count count+=1 print(sum)

    5、用户登陆(三次机会重试)

    i=0 while i<3: username=input('请输入账号') password=int(input('请输入密码')) if username=='小陈'and password=='123'print('登录成功'else: print('登录失败') i+=1
    Processed: 0.021, SQL: 9