Chapter 3 reserved words, identifiers and built-in functions of the foundation of Python

Web front end practice log 2021-01-19 06:24:04
chapter reserved words identifiers built-in


One 、 Reserved words ( keyword )

Reserved word is python Some words in a language that have been given a specific meaning , This requires developers to develop programs , You can't use these reserved words as identifiers for variables 、 function 、 class 、 Templates and other object naming .

Python List of reserved words

and as assert break class continue
def del elif else except finally
for from False global if import
in is lambda nonlocal not None
or pass raise return try True
while with yield

It should be noted that , because Python It's strictly case sensitive , Reserved words are no exception . therefore , We can say if Is a reserved word , but IF It's not reserved words .

Two 、 identifier

Simply understand , An identifier is a name , It's like each of us has his own name , Its main function is as a variable 、 function 、 class 、 Names of modules and other objects .

python The identifier is not named arbitrarily , It's about following certain rules of command , for instance :

(1) An identifier is made up of characters (A~Z and a~z)、 Underline and numbers make up , But the first character cannot be a number .

(2) Identifiers cannot be with Python The reserved words in are the same . About reserved words , The following chapters will describe in detail .

(3) Python In the identifier in , Cannot contain spaces 、@、% as well as $ Equal special character

(4) stay Python in , The letters in the identifier are Case sensitive Of , in other words , Two identical words , If the size format is different , The meaning of multi representation is also completely different . for instance , The following 3 Between two variables , It's completely independent 、 It doesn't matter , They are independent of each other .

number = 0
Number = 0
NUMBER = 0

(5) Python In language , Identifiers that begin with underscores have a special meaning , for example :

  • · An identifier that starts with a single underline ( Such as _width), Represents a class property that cannot be accessed directly , It cannot pass from...import* How to import ;
  • · Identifiers starting with double underscores ( Such as __add) Represents a private member of a class ;
  • · Identifiers that start and end with double underscores ( Such as __init__), Is a private identifier .

therefore , Unless a particular scenario requires , You should avoid using identifiers that start with underscores .

Let's get familiar with it again Python Some common naming conventions :

(1) Module name : Try to be short , And use all lowercase letters , have access to “_” Split multiple letters , for example :game_main、game_regsiter;

(2) Package name : Also try to be short , And use all lowercase letters , Underline is not recommended . for example :com.mingrisoft、com.mr;

(3) Class name : Capitalize a word ( namely Pascal style ), for example : Define a book borrowing class :BorrowBook.

(4) Classes inside modules : Underline “_”+Pascal The class name of the style , for example : stay BorrowBook The inner class of a class :_BorrowBook

(5) function 、 Class properties and method naming rules : Similar to module name , It's also all lowercase letters , Multiple letters can be used “_” Separate

(6) Constant : All in capital letters , You can use underscores “_”

(7) Use single underline “_” The starting module variable or function is protected , In the use of from XXX import * When a statement is imported from a module, these variables or functions cannot be imported

(8) Double underline “__” The first instance variable or method is private to the class .

3、 ... and 、 Built in functions

ptthon The functions that come with the interpreter are called built-in functions , These functions can be used directly , There is no need to import a module

surface by Python 3.x Built in functions

abs() delattr() hash() memoryview() set()
all() dict() help() min() setattr()
any() dir() hex() next() slicea()
ascii() divmod() id() object() sorted()
bin() enumerate() input() oct() staticmethod()
bool() eval() int() open() str()
breakpoint() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()
版权声明
本文为[Web front end practice log]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/01/20210116173041725e.html

  1. 小白量化投资交易入门课(python入门金融分析)
  2. Python:PyCharm选择性忽略PEP8警告
  3. Python: pychar selectively ignores pep8 warnings
  4. Django-模板
  5. Django template
  6. Python正则表达式大全
  7. 最全Python正则表达式来袭
  8. A python knowledge for Xiaobai
  9. 2. Flexible pandas index
  10. 1. Get to know pandas
  11. See how I use Python to create a magic with baby (one play can play for a day)?
  12. Wow, python can do real-time translation
  13. Python经典编程习题100例
  14. 100 examples of Python classic programming exercises
  15. Invincible, with Python for English teachers to develop a magic tool for English composition correction (support primary school to IELTS)
  16. 抖音数据采集教程,最全python库selenium自动化使用
  17. Pandas 11-综合练习
  18. Pandas 11 - comprehensive exercises
  19. Pandas基础|用户游览日志时间合并排序
  20. python自学 第三章 python语言基础之保留字、标识符与内置函数
  21. python学习例程3-函数
  22. Python GUI 之Tkinter小结 - 知乎
  23. Pandas foundation | user travel log time merge sort
  24. Tkinter summary of Python GUI - Zhihu
  25. 【Python常用包】itertools
  26. Itertools
  27. [Python] Matplotlib 图表的绘制和美化技巧
  28. Drawing and beautifying skills of [Python] Matplotlib chart
  29. Drawing and beautifying skills of [Python] Matplotlib chart
  30. Python序列之列表(一)
  31. Python解析库lxml与xpath用法总结
  32. Python解析库lxml与xpath用法总结
  33. Usage Summary of Python parsing library lxml and XPath
  34. Usage Summary of Python parsing library lxml and XPath
  35. Python web/HTML GUI
  36. Why is sanic better than Django flame?
  37. Wechat applet Python sends subscription message
  38. Invincible, with Python for English teachers to develop an English composition correction artifact (support primary school to IELTS)
  39. How can I use Python to create a magic with children (one can play for one day)?
  40. Pandas module
  41. Machine learning in Python - Boston house price forecast
  42. 50 Great Python modules
  43. Share the survival status of Python practitioners and tell you the real salary of general programmers
  44. Pandas basic operation update
  45. Python Programming day02 Python operator
  46. Usage Summary of Python parsing library lxml and XPath
  47. 1. First meeting pandas
  48. Conversion between Python and base conversion between Python and base
  49. Basics of Python
  50. Fundamentals of python (XIV): errors and exceptions
  51. Fundamentals of python (8): time related modules
  52. Fundamentals of python (I): necessary knowledge for getting started
  53. Operators in Python 3
  54. The list of national computer non graduate schools (captured by Python), just look at this one!
  55. Python data visualization: Seaborn
  56. Quick start pandas (lower)
  57. Operators in Python 3
  58. Python tarfile module
  59. Python basic syntax