While循环 Carol

1,python 历史。

官方发布2020年将全部统一使用3.x版本。2.x源码不标准,重复代码太多。3.x统一标准,去除了重复代码。

2,python的环境。

    编译型:一次性将所有程序编译成二进制文件。

       缺点:开发效率低,不能跨平台。

      优点:运行速度快。

    C,C++等。

    解释型:当程序执行时,一行一行的解释。

      优点:开发效率高,可以跨平台。

      缺点:运行速度慢。

    Python,Php等。

3,python的种类。

  在cmd下运行:

    python3.x :python 文件 回车

    PYTHON2.x:python2 文件 回车

  2.x与3.x的区别:2.x默认编码方式是ASCII码。解决方式:在文件的首行:#-*- encoding utf-8 -*-。

  python3.x的默认编码方式是utf-8。

4,变量与常量。

    变量就是将一些运算的中间结果暂存到内存种,以便后续代码调用。

    变量必须由数字,字母,下划线任意组合,不能以数字开头。不能用Python的关键字。

    常量就是一直不变的量。

5,注释。

    单行:#

    多行:‘’‘ en ’‘’,"""hai"""

6,用户交互。input

      !!!!!!!!注意!!!!!!!!

      input出来的数据类型全部都是str类型。!

      !!!!!!!注意!!!!!!!!!

7,基础数据类型初始。

      略....

      type()查看数据类型。

      字符串转化成数字:int(str) 条件:str必须是数字组成的。

      数字转化成字符串:str(int)

      字符串: str,python中凡是引号里面的都是字符串。字符串可以相加,相乘(str*int)。

      bool值:布尔值。Ture False

8,if语句。

if 条件:

  结果

1 a = 11
2 b = 10
3 if a>b:
4     print('a大于b')

9,while语句。

while 条件:

  循环体

  无限循环

1 print('hello')
2 while True:
3     print('nihao')
4     print('wohao')
5     print('dajiahao')
6 print('hi')
7 #whlie 无限循环循环体。
 1 #1-100顺序输出
 2 '''
 3 #方法1
 4 count = 1
 5 flag = True
 6 #标志位
 7 while flag:
 8     print(count)
 9     count = count + 1
10     if count > 100 :
11         flag = False
12 '''
13 '''
14 #方法2
15 count = 1
16 while count <= 100:
17     print(count)
18     count = count + 1
19 '''
20 '''
21 #方法3
22 count = 1
23 sum = 0
24 
25 while count <= 100:
26     sum = sum + count 
27     count = count + 1
28     
29 print(sum)
30 '''
1-100顺序输出


 


 

终止循环:1,改变条件,使其不成立。

       2,break

'''
print('11')
while True:
    print('222')
    print(333)
    break
    print(444)
print('abc')
'''
count = 1
while True:
    print(count)
    count = count + 1
    if count > 100:break
break示例

continue:终止上一循环继续下个循环。跳出本次循环,相当于循环底层

continue示例
 
原文地址:https://www.cnblogs.com/qinghuani/p/8039378.html