Python基础学习lesson3

白癜风有哪些表现症状 http://pf.39.net/bdfyy/jdsb/160324/4800901.html
python的基础知识:42来自LearningYard学苑

Part1字符串和字节串

1.使用`’`、`”`、`’’’`、`”””`作为定界符来表示字符串,不同定界符间可互相嵌套

2.Python3.x全面支持中文,可用中文作为变量名

1.Use’,”,’’’,”””asdelimiterstorepresentcharacterstrings,anddifferentdelimiterscanbenestedwithineachother

2.Python3.xfullysupportsChinese,andChinesecanbeusedasvariablenames

3.str字符串和bytes字节串的转换

3.Conversionofstrstringandbytesbytestring

Part2列表、元组、字典、集合

注:所有的索引都从0号位开始。

Part3运算符

1.算术运算符优先级最高,其次是位运算符、成员测试运算符、关系运算符、逻辑运算符等,算术运算符遵循“先乘除,后加减”的基本运算原则

2.使用圆括号来明确说明其中的逻辑来提高代码可读性

1.Arithmeticoperatorshavethehighestpriority,followedbybitwiseoperators,membertestoperators,relationaloperators,logicaloperators,etc.Thearithmeticoperatorsfollowthebasicoperationprincipleofmultiplyanddividefirst,thenaddandsubtract

2.Useparenthesestoclearlyexplainthelogictoimprovecodereadability

Part4算数运算符

+的使用

*的使用

/和//的使用

%的使用

注:A的ascii码是65。

**的使用

Part5关系运算符

Python关系运算符最大的特点是可以连用

连续使用时,关系运算符具有惰性求值的特点

ThebiggestfeatureofPythonrelationaloperatorsisthattheycanbeusedtogether

Whenusedcontinuously,relationaloperatorshavethecharacteristicsoflazyevaluation

示例:

导入math模块,才能调用math。

in用于成员测试,即测试一个对象是否为另一对象的元素。

`in`isusedformembertesting,thatis,totestwhetheranobjectisanelementofanotherobject.

is测试两个对象是否是同一个,若为同一个,则具有相同内存地址。

Part6集合运算符

Part7逻辑运算符

and和or具有惰性求值特点,当连接多个表达式时只计算必须要计算的值

合理安排不同条件的先后顺序,一定程度上可提高代码运行速度

运算符`and`和`or`并不一定会返回`True`或`False`,而是得到最后一个被计算的表达式的值,但是运算符`not`一定会返回`True`或`False`

Andandorhavethecharacteristicsoflazyevaluation,whenmultipleexpressionsareconnected,onlythevaluethatmustbecalculatediscalculated

Reasonablyarrangethesequenceofdifferentconditions,whichcanimprovethecoderunningspeedtoacertainextent

Theoperators`and`and`or`donotnecessarilyreturn`True`or`False`,butgetthevalueofthelastcalculatedexpression,buttheoperator`not`willdefinitelyreturn`True`or`False`

参考资料:谷歌翻译

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




转载请注明:http://www.aierlanlan.com/grrz/1313.html