Lesson 6 python for loop and while loops

 之前学习C语言的时候,语法之类的都不是很懂,但是已经知道 3个情况 ---流程
     1. 顺序 编写(一步一步下去)执行按照上到下;
     2. 判断 编写。(就是 如果符合什么条件,就做什么。。。。)
     3. 循环 编写。(符合特定条件,进行重复的事情)

###到了python,我们上一个课,说了if,这里说循环;你不是要问 顺序 不说吗?自己脑补一下(不需要理会任何条件的,一个个代码执行下去,不是顺序?)

for循环和while循环
-----------------------------------我觉得2个没有明显区别。只是for 倾向 有范围性重复的工作(例如:range(1,10);你会觉得while不行吗?行的,也可以实现,只是代码量 跟 习惯问题而已。

#####for循环
---------for循环开始之前,我们要说一下 格式:
for i in 对象:
    print(i)

--------- If you read, you are basically beginning. . .
i ## variables, sometimes the programming language in time for the variables need to be defined in advance (but not in basic python for)
the object ## Why, I am here to write an object? Are all objects can be placed for here? (Not all, but basically all OK, now I see)
: ## Main: Symbol

for i in [1,2,3,4,5] :
    print(i)

或者 
number = [1,2,3,4,5]
for i in number :
    print(i)

####会不会发现 in 后面就是放对象的,对象可以是:
name = "samly71"     ### 字符串
number = [1,2,3,45]   ###列表
dict1 = ["samly71"=18,"your age"=38]  ###字典
f = open("a.txt","r")    #####打开一个文件,也可以在for循环,是不是很普通,长江。

PS: numeber1 = 100 ###是否能放到 for i in number1:  ###是的整数,浮点都不能这样for,
但是可以for i in range(1,100) ###因为range(1,100) 是列表

for that simple. . .

#####while循环 ,符合条件的,就开始循环,直到不符合退出

a = 100
while a <=100:
    print(a)
        a +=1

是不是只会打印1次100。。。。是的。。。
a +=1 什么意思? a = a+1 你说什么意思,术语叫自加 (去看看变量的定义)-变量 像 门牌号 & 对象 像 房子。(还没想象到的,回头找我吧)

----说明一下 比较的符号
a <= 100 小于等于
==     等于
!=      不等于 
>100
<100
in

in not
---- these conditions are more symbolic. . . Google.baidu use it. . . Anyway, I do not always remember.

循环入门基本到这里了,就这样简单。我们这里说一个range() 函数。。请回顾我们 6个课,多少函数了。(一定要熟悉,真不多,你必须清楚会用,因为他们经常用,你可以得心应手地完成基本工作。。。

print()
input()
type()

------------------ used in List, dict -------------------
len ()
the append ()
POP ( )

In the range of numbers used ------------------ -------------------
Range ()

Guess you like

Origin blog.51cto.com/323248/2426425