Basic Python exercises

Source: Internet
Author: User

1. Why does python not need variable name and variable type declaration?
In python, the object type and memory are determined at runtime. When a value is created, the interpreter determines the type of the new object based on the syntax and the right operand.
2. Why does python not need to declare function types?
To be supplemented
3. Why should I avoid double underscores (_) at the beginning and end of the variable name in python?
Legal identifier:
-The first character must be a letter or underscore (_).
-The remaining characters can contain letters, numbers, and underscores.
-Case Sensitive
Python uses underlines as the prefix and suffix of variables to pin special variables.
-_ Xxx _ system definition name
-_ Xxx is not imported from 'from module import' or from module
-The private variable name module in the _ xxx class is not available except the class.
4. How does python write multiple statements in one row?
Multiple statements written in the same row of books are separated by a comma.
Example: import sys; x = 'foo'; sys. stdout. write (x + '\ n ')
Writing a single row of books greatly reduces readability and is not recommended.
5. How to Write multiple lines of books in the same python statement?
If the statement is too long, you can use the Backslash "\" to break it into several lines.
Example: if (a = 1) and \
(B = 0 ):
In exceptional cases, when the closed operator is used, a single statement can span multiple rows.
For example, you can write multiple lines of books in brackets, Parentheses, and curly brackets.
When assigning values to variables:
A. B. c. d = (1,
2, 3, 4)
Display a string with three quotation marks
Printf ''' aaaaaaaaaaaaaaaaaaaa
Aaaaaaaaaaaa '''
6. Variable assignment exercise
(A) values of x, y, z = 1, 2, 3 x, y, and z are obtained respectively.
& Gt; x 1
& Gt; y 2
& Gt; z 3
(B) What are the values of z, x, y = y, z, x, x, y, and z after execution?
& Gt; x 3
& Gt; y 1
& Gt; z 2

 


From the nevasun Column

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.