Python基础学习lesson1

Python第十课的基础知识01:58来自LearningYard学苑

01条件表达式

选择或循环结构中,若条件表达式值不为Falsea、0、None等值,则皆认定为True

Intheselectionorloopstructure,ifthevalueoftheconditionalexpressionisnotFalsea,0,None,etc.,itwillallberegardedasTrue

1.关系运算符:可连用

1.Relationaloperators:canbeusedtogether

2.不允许使用赋值运算符=

2.Theassignmentoperator=isnotallowed

3.逻辑运算符and和or具备惰性求值的特征

3.Thelogicaloperatorsandandorhavethecharacteristicsoflazyevaluation

02选择结构

单分支、多分支、跳转分支、嵌套分支

Singlebranch,multiplebranch,jumpbranch,nestedbranch

1.单分支选择结构

Singlebranchselectionstructure

2.双分支选择结构

2.Doublebranchselectionstructure

例:鸡兔同笼问题

Example:Chickenandrabbitinthesamecage

三元运算符:value1ifconditionelsevalue2

当条件表达式condition的值与True等价时,表达式的值为value1,否则表达式的值为value2

Ternaryoperator:value1ifconditionelsevalue2

WhenthevalueoftheconditionalexpressionconditionisequivalenttoTrue,thevalueoftheexpressionisvalue1,otherwisethevalueoftheexpressionisvalue2

03多分支选择结构

例:将成绩按百分制转换为等级制

Example:Convertthegradesfromahundred-pointsystemtoagradesystem

循环结构

01while语句

1.while:一般用于循环次数难以提前确定的情况,当然也可以用于循环次数确定的情况

1.while:Generallyusedinsituationswherethenumberofcyclesisdifficulttodetermineinadvance,ofcourse,itcanalsobeusedinsituationswherethenumberofcyclesisdetermined.

猜数字游戏

Guessthenumbergame

02for语句

for:一般用于循环次数可以提前确定的情况,尤其适用于枚举或遍历

for:Generallyusedinsituationswherethenumberofloopscanbedeterminedinadvance,especiallyforenumerationortraversal

使用循环结构遍历并输出列表的所有元素

Usealoopstructuretotraverseandoutputallelementsofthelist

输出1~之间能被7整除且同时被5整除的所有整数

Outputallintegersbetween1andthatcanbedivisibleby7andatthesametimeby5

打印九九乘法表

Printnine-ninemultiplicationtable

03break和continue语句

break:结束循环

continue:结束本次循环,进入下一次循环

break:endtheloop

continue:Endthiscycleandenterthenextcycle

参考资料:谷歌翻译

本文由LearningYard学苑原创,如有侵权,请联系删除。




转载请注明:http://www.aierlanlan.com/rzdk/1329.html