Python基础学习lesson4

Python第四课的基础知识02:24来自LearningYard学苑

01关键字

1.python关键字不允许通过任何方式改变它们的含义,也不能用来做变量名、函数名或类名等标识符

2.在Python开发环境中导入模块keyword之后,可以使用print(keyword.kwlist)查看所有关键字

1.Pythonkeywordsarenotallowedtochangetheirmeaninginanyway,norcantheybeusedasidentifierssuchasvariablenames,functionnames,orclassnames

2.AfterimportingthemodulekeywordinthePythondevelopmentenvironment,youcanuseprint(keyword.kwlist)toviewallkeywords.

02内置函数

1.类型转换与类型判断

ord()和chr()是一对功能相反的函数,ord()用来返回单个字符的Unicode码,而chr()则用来返回Unicode编码对应的字符,str()则直接将其任意类型参数转换为字符串。ord()andchr()areapairoffunctionswithoppositefunctions,ord()isusedtoreturntheUnicodecodeofasinglecharacter,whilechr()isusedtoreturnthecharactercorrespondingtotheUnicodeencoding,andstr()directlyconvertsittoanytypeTheparameterisconvertedtoastring.

list()、tuple()、dict()、set()、frozenset()用来把其他类型的数据转换成为列表、元组、字典、可变集合和不可变集合,或者创建空列表、空元组、空字典和空集合。

list(),tuple(),dict(),set(),frozenset()areusedtoconvertothertypesofdataintolists,tuples,dictionaries,variablecollectionsandimmutablecollections,ortocreateemptylistsandemptyelementsGroups,emptydictionaries,andemptycollections

内置函数type()和isinstance()可以用来判断数据类型,常用来对函数参数进行检查,可以避免错误的参数类型导致函数崩溃或返回意料之外的结果。

Thebuilt-infunctionstype()andisinstance()canbeusedtodeterminethedatatype.Theyareoftenusedtocheckfunctionparameters,whichcanpreventthefunctionfromcrashingorreturningunexpectedresultsduetoincorrectparametertypes.

max()、min()、sum()计算列表、元组或其他包含有限个元素的可迭代对象中所有元素最大值、最小值以及所有元素之和。

max(),min(),sum()calculatethemaximumvalue,minimumvalueandthesumofallelementsinalist,tupleorotheriterableobjectcontainingafinitenumberofelements.

03基本输入输出

input()和print()是Python的基本输入输出函数

input()一律返回字符串对待

input()andprint()arethebasicinputandoutputfunctionsofPython

input()alwaysreturnsastringtobetreated.

内置函数print()用于输出信息到标准控制台或指定文件

sep参数之前为需要输出的内容(可以有多个)

sep参数用于指定数据之间的分隔符,默认为空格

end参数用于指定输出完数据之后再输出什么字符

file参数用于指定输出位置,默认为标准控制台,也可以重定向输出到文件

Thebuilt-infunctionprint()isusedtooutputinformationtothestandardconsoleorspecifiedfile

Beforethesepparameteristhecontenttobeoutput(therecanbemorethanone)

Thesepparameterisusedtospecifytheseparatorbetweenthedata,thedefaultisaspace

Theendparameterisusedtospecifywhatcharacterstooutputafterthedataisoutput

Thefileparameterisusedtospecifytheoutputlocation,thedefaultisthestandardconsole,youcanalsoredirecttheoutputtoafile

参考资料:谷歌翻译

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




转载请注明:http://www.aierlanlan.com/rzgz/1963.html