Print can PRint multiple expressions, as long as they are separated by commas, a space will be inserted between each parameter in the result. using + can avoid spaces, such as print-related
Print can print multiple expressions, as long as they are separated by commas (,), a space is inserted between each parameter in the result. use + to avoid spaces, as shown in figure
>>> Print 'age: ', 42
Age: 42
>>> Print 'hello' + ',' + 'world'
Hello, world
Add a comma at the end of the print statement. The following statement is printed in the same line as the previous statement, as shown in figure
Print 'hello', print 'world'
Result
>>>
Hello world
Import problems
From sometmodule import somefunc, anotherfunc, yetanotherfunc
From somemodule import * -- import all functions in the module
Import somemoudle as othermodulename -- give the module an alias
Form somemodule import somefunc ad otherfuncname -- alias for the imported function
Assignment
Sequence unpacking or optional replacement-unpacks the sequence of multiple values and then stores them in the sequence of variables, as shown in figure
>>> Scoundrel = {'name': 'Robin ', 'firlfriend': 'Marion '}
>>> Key, value = scoundrel. popitem ()
>>> Key
'Firlfriend'
>>> Value
'Marion'
Chained assignment -- shortcut for assigning the same value to multiple variables, such
X = y = somefunction ()
Incremental value assignment: place the expression operator on the left of the value assignment operator =, as shown in figure
X + = 1
Statement block
Colon (:) is used to identify the beginning of the statement block. each statement in the block is indented (with the same number of indentations ). When it is rolled back to the same indentation as the closed block, it indicates that the current block has ended.
Threesome
Pass -- the program does not need to do anything.
Del -- delete the object, but it does not affect the value, as shown in figure
>>> X = y = [1, 2]
>>> Y [1] = 'p'
>>> Y
[1, 'P']
>>> X
[1, 'P']
>>> Del x
>>> X
Traceback (most recent call last ):
File" ", Line 1, in
X
NameError: name 'X' is not defined
>>> Y
[1, 'P']
Exec -- execute a string statement
>>> Exec ("print 'Hello, world! '")
Hello, world!
Eval -- evaluate the value of an expression
>>> Eval ("4 + 56 ")
60
The above is the content of other statement 1 in the "python basic tutorial" notes. For more information, see The PHP Chinese website (www.php1.cn )!