In general, the access rules for class instance properties are more intuitive in python.
However, there are still some areas that are not intuitive, especially for C + + and Java programmers.
Here, we need to understand the following areas:
1.Python is a dynamic language in which any entity can dynamically add or remove attributes.2. A class defines a scope.3.
Python naming rules
Python identifier
See: https://docs.python.org/3/reference/lexical_analysis.html? Highlight = identifier # identifiers
In python, identifiers consist of letters, numbers, and underscores, and cannot use reserved words in Python.
In
Python has the following basic rules:#后表示注释\ n is the line delimiter\ is to continue on the previous line, separating the long statement; Semicolon joins two statements in one row: Colon separates Dock and bodyCode blocks are represented by indented blocksDifferent indentation depths separate different blocks of codePython files are organized in the form of modulesIndent the recommended style, indent four s
This article describes the python development rules. For more information, see 1. Python advantages: simple, elegant, and clear python disadvantages.
2. powerful module three-bedroom Library 1. code cannot be encrypted
3. ease of transplantation 2. slow speed
4. object-oriented
5. scalability (c \ java \ c #....)
Cpyt
, we are basically familiar with the code conversion rules in the Python environment, the rest of the coding operation process is the same.Summarize:When transcoding, we need to know the default encoding format of the current version of the Python interpreter as it runs the program. On this basis, when we do the encoding conversion, remember: Unicode encoding is
Basic Tutorial oq=python%e5%9f%ba%e7%a1%80%e6%95% 99%e7%a8%8brsv_pq=bc14fc45000148d3rsv_t=1cc4h7yncotnc5/ejw6ufw/ Ab8klfjbeowxnae8ogbhh8towwqhoy4bkrckpq6xra2jquqrqlang=cnrsv_enter=0After decoding can be seen to search for the basic Python tutorial2. Requirements for signature rulesThe requirements are as follows:A, input data:1. Request data:vendorid=1697poscode=pos006ip=127.0.0.1posversion=2.1.1.1.1mac=;D
Python has a variety of packages, so what rules does the Python interpreter use to look for packages?1. Python will first look for a built-in (BUILT_IN) package2. Then search in order according to the path specified in the PYTHONPATH environment variable.3. Then search by the path specified in the. pth file that can be
We all know Graminit. c defines the content related to the actual application of Python syntax rules, including some typical types. If you want to know which four typical types are involved, you can read the following articles to learn about it.
Grammar. hGraminit. c defines the DFA (Deterministic Finite Automaton) that includes Python syntax
Let's look at the inheritance of Python classes in this article, and for a friend who has just come into contact with Python's programming language, there should be less knowledge of the Python class's inheritance, but it's okay, in the next article we'll look at
inheritance rules for Python classes, I'll be in the fol
1. Multi-Objective assignment2. Multi-objective assignment and shared referenceThere's no problem with non-mutable objects, but for mutable objects, there's a problem here.The above example AB is immutable, so when B changes, the object that B points to has been re-created.Because the list is mutable, AB points together to the same list, so when B changes, a also changes3. Enhanced AssignmentEnhanced assignment is the use of +=,>= and other operators to assign values, here are two examples4. Enh
#[' http://www.qidian.com/', '/HTTP/ www.qidian.com/']At this point, if the match returns the result is a list.The haunting of the backslashPat = re. Compile(R ' href= "([^"]*) ")There is an ' r ' in the regular meaning of the native string, which means that it is not escaped, for example: Path="c:\noway"print path# C:# owaypath=r"c:\noway"print path# C:\nowayThe regular expression uses "\ \" to denote a backslash symbol, so when you want to match "\ \" in the string with "\\\\", the first t
, and if not, correct them. Warning do not become slaves to these rules in everyday programming. In training, you need to use these rules to consolidate the knowledge you have learned, and in practical programming these rules are sometimes stupid. If you think that rule is stupid, don't use it.rules of the loop1. Use the "while loop" only when the loop never stop
._foo__a, to avoid ambiguity. If the subclass is also called Foo, there is nothing you can do about it.Methods of class 13 The first argument must be self, and the first parameter of the static method must be CLS.Seven coding recommendationsThe 1 encoding takes into account the efficiency of other Python implementations, such as the high efficiency of the operator ' + ' in CPython (Python), which is very lo
, immutable collection
Python data type (by variability)
Hash, immutable data type: Numeric type, immutable collection, string, tuple
mutable data types: Dictionaries, lists, mutable collections
Convert utf-8 name.encode (' Utf-8 ') Cancel Name.decode (' Utf-8 ')
Program if you want to save Chinese
#_ *_ Coding:utf-8 _*
Name=u "Chinese"
Print Name
To interact with the system to save files
Import OS
A=os.popen (' pwd '). Read ()
A
Import commands
Res =
and instance variables. To avoid conflicts with subclass naming, two leading underlines are used to trigger the naming Reorganization rules of Python. Python uses the class name to rename these names: if the class Foo has an attribute named _ a, it cannot be accessed with Foo. _. (Persistent users can still obtain access through Foo. _ Foo _ .) Generally, the do
1. Tuples(1) Tuples look like lists, but are identified using parentheses instead of square brackets. Once you have defined a tuple, you can use the index toAccess its elements just as you would access a list element.(2) The elements of a tuple cannot be modified, but can be assigned values.2. Rules(1) Indent: It is recommended to use four spaces for each level of indentation, which improves readability and leaves enough multi-level indentation space.
I,Package name, Module name, local variable name, function name
All lower case + underlined hump
Example: this_is_var
2. Global Variables
Full upper case + underlined hump
Example: GLOBAL_VAR
Iii. Class Name
Upper-case hump
Example: ClassName ()
4. Underline
Example for 1:
The variables var_1, _ var_2, _ var_3 are defined in the module_1 module.
The code in the module_2 module is as follows:
module_1 * _var_2
An error will be reported when you execute lines 6 and 7, becaus
And: If the expression is not false, the value of the last expression is returned, and if the first expression is false, the value is false. (the value of this expression is returned when a false expression is encountered)Or: If both are false, the value of the last false expression is returned, and if true, the first true value is returned. (Returns the value of this expression when a true expression is encountered)The priority of and is greater than orAnd,or calculation
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.