What are the reserved words in Python? Let me introduce to you a summary of Python’s 33 reserved words:
1 false
#Boolean type value, indicating false, corresponding to true
2 class
#Keywords for defining classes
##3 finally
#Exception The keyword used in processing can be used to specify the code that is always executed. The specified code is in finallyFor example:class MyException(Exception):pass try: #some code here raise MyException except MyException: print "MyException encoutered" finally: print "Arrive finally"
4 is
# Objects in Python contain three elements: id, type, valueid: used to uniquely identify an object
type: identifies the type of the object
value: Is the value of the object
is: It is used to determine whether the a object is the b object. It is judged by the id.
python video tutorial"
For example:>>> a = 1 >>> b = 1.0 >>> a is b False >>> a == b True >>> id(a) 12777000 >>> id(b) 14986000
5 return#Python function returns the value return. There must be a return value in the function to be a complete function. If you do not define a function return value in Python, then you will get a None object as a result, and None means there is no value.
def fnc1(x,y): print x+y 当函数没有显示return,默认返回none值,以下测试: >>> result = fnc1(2, 3) >>> result is None True7 continue #The continue statement is used to tell Python to skip the remaining statements in the current loop block and continue. Next cycle.
8 for
#The for loop can traverse any sequence of items, such as a list or a string>>> type(None)
<class 'NoneType'>
>>> None == 0
False
>>> None == ''
False
>>> None == None
True
>>> None == False
False
9 lambda
For example: exists for the definition of a single-line function.
10 try
12 def
# used to define functions. For example: for letter in 'Python': # 第一个实例
print '当前字母 :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # 第二个实例
print '当前水果 :', fruit
print "Good bye!"
13 from
14 nonlocal
For example:
g = lambda x:x+1
15 while
#The while statement repeatedly executes a block of statements. while is a type of loop statement that has an optional else clause.
16 and
#Logical judgment statement, if both the left and right sides of and are true, then the judgment result is true, otherwise both are false
17 del
#del is used for list operations to delete one or several consecutive elements.
For example: g(1)
>>>2
g(2)
>>>3
g(7)
>>>8
18 global
#Define a global scalar.
19 not
#Logical judgment, the meaning of inversion
20 with
#with is available after python2.5 Yes, it is essentially a control flow statement. with can be used to simplify the try...finally statement. Its main usage is to implement a class _enter_() and _exit_() method.
For example: >>> foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
>>>
>>> print filter(lambda x: x % 3 == 0, foo)
[18, 9, 24, 12, 27]
>>>
>>> print map(lambda x: x * 2 + 10, foo)
[14, 46, 28, 54, 44, 58, 26, 34, 64]
>>>
>>> print reduce(lambda x, y: x + y, foo)
21 as
# Used in conjunction with with.
22 elif
# Used with if
24 or
25 yield
#yield is used like return. Yield tells the program to require the function to return a generator
For example:
def hello() print('hello,hongten') 调用: hello() 结果: >>>hello,hongten
26 assert
#Assertion is used to check the correctness of the program during operation, and has the same function as other languages.
For example:
def make_counter(): count = 0 def counter(): nonlocal count count += 1 return count return counter def make_counter_test(): mc = make_counter() print(mc()) print(mc()) print(mc())
27 else
#Use with if
28 import
#at Python uses import or from...import to import the corresponding module. For example:
from sys import * print(‘path’,path)
29 pass
#pass的意思是什么都不要做,作用是为了弥补语法和空定义上的冲突,它的好处体现在代码的编写过程之中,比如你可以先写好软件的整个框架,然后再填好框架内具体函数和class的内容,如果没有pass编译器会报一堆的错误,让整个开发很不流畅。
例如:
def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods(yet)
30 break
#break语句是用来终止循环语句的,即使哪怕循环条件没有称为false或者序列还没有被完全递归,也会停止循环语句。提示,如果break的是for或while循环,任何对应的循环else块将不执行。
31 except
#使用try和except语句来铺货异常。
32 in
#for…in是另外一个循环语句,它在一序列的对象上递归即逐一使用队列中的每个项目。
33 raise
#raise抛出异常。
例如:
class MyException(Exception):pass try: #some code here raise MyException except MyException: print('MyException encoutered') finally: print('Arrive finally')
The above is the detailed content of What are the reserved words in Python?. For more information, please follow other related articles on the PHP Chinese website!

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function