Other statements of the Python Basic tutorial Note 1

Source: Internet
Author: User
PRint related

Print prints multiple expressions, as long as they are separated by commas, and a space is inserted between each parameter in the result, using + to avoid spaces, such as

>>> print ' Age: ', 42
Age:42
>>> print ' hello ' + ', ' + ' world '
Hello,world

Add a comma at the end of the print statement, and the next statement will be printed on the same line as the previous statement, such as

print ' Hello ', print ' world '

Results

>>>
Hello World

Import related

From Sometmodule import Somefunc,anotherfunc,yetanotherfunc

From somemodule Import *--all functions in the import module

Import Somemoudle as Othermodulename--take individual names for modules

Form Somemodule Import SomeFunc ad otherfuncname--Take an individual name for the imported function

Assignment correlation

Sequence unpacking or optional generation of unpacking--the sequence of multiple values is unpacked and then placed in the sequence of variables, as

>>> scoundrel = {' name ': ' Robin ', ' firlfriend ': ' Marion '}
>>> Key,value = Scoundrel.popitem ()
>>> Key
' Firlfriend '
>>> value
' Marion '

Chained assignment-A shortcut that assigns the same value to multiple variables, such as

X=y=somefunction ()

Increment assignment--place the expression operator on the left side of the assignment operator =, as

x + = 1

Statement block

The colon (:) is used to identify the beginning of the statement block, and each statement in the block is indented (the indent is the same). When you fall back to the same indent as an already closed block, it means that the current block is closed.

Three-person line

Pass--The program doesn't have to do anything.

Del-Deletes the object without affecting the value, such as

>>> x = y = [+]
>>> y[1] = ' P '
>>> y
[1, ' P ']
>>> x
[1, ' P ']

>>> del X
>>> x

Traceback (most recent):
File "<pyshell#51>", line 1, in <module>
X
Nameerror:name ' x ' is not defined
>>> y
[1, ' P ']

EXEC--A statement that executes a string

>>> exec ("print ' Hello, world! '")
Hello, world!.

Eval--To find the value of an expression

>>> eval ("4 + 56")
60

The above is the "Basic Python Tutorial" notes of the other statement 1 content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.