Basic Python Tutorials
Http://www.w3cschool.cc/python/python-tutorial.html
- Python is a high-level scripting language that combines explanatory, compiled, interactive, and object-oriented.
- Python is an interpreted language: this means that there is no compilation in the development process. Similar to the PHP and Perl languages.
- Python is an interactive language: This means that you can execute your program in a Python prompt directly interacting with the execution.
- $ chmod +x test.py # script file Add executable permissions
- In Python, all identifiers can include English, numeric, and underscore (_), but cannot begin with a number.
- Identifiers that begin with an underscore are of special significance. A class attribute that begins with a single underscore, which is not directly accessible by the _foo, must be accessed through the interface provided by the class and cannot be imported with the FROM XXX import *;
- A __foo that begins with a double underscore represents the private member of the class;
- A __foo__ that begins and ends with a double underscore represents a special method-specific identifier for Python, such as __init__ (), which represents the constructor of a class.
- Python can display multiple statements on the same line, separated by semicolons .
- The biggest difference between learning Python and other languages is that Python's code block does not use curly braces {} to control classes, functions, and other logical judgments. Python's most distinctive feature is the use of indentation to write modules.
- A new line is generally used as the Terminator for a statement in a Python statement. But we can use a slash (\) to divide a line of statements into multiple lines of display. The statement contains [], {}, or () parentheses do not need to use a multiline connector.
- A single-line comment in Python starts with #. Comments can be at the end of a statement or an expression line. A multiline comment in Python uses three single quotation marks ("') or three double quotation marks (" ").
- The print default output is newline, and if you want to implement no wrap, you need to add a comma to the end of the variable.
- Indenting the same set of statements constitutes a block of code, which we call the code group. Compound statements such as if, while, Def, and class, the first line begins with a keyword, ends with a colon (:), and one or more lines of code after that line form the code group. We refer to the first line and the following code group as a clause (clause).
- Variable assignments in Python do not require a type declaration. Each variable is created in memory and includes information about the identity, name, and data of the variable. Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned.
- Python allows you to assign values to multiple variables at the same time. You can also specify multiple variables for multiple objects.
- Python has five standard data types: Numbers (numeric), string (string), list (lists), tuple (tuple), Dictionary (dictionary)
- They are immutable data types, which means that changing the numeric data type assigns a new object. When you specify a value, the number object is created. You can delete a reference to a single or multiple objects by using the DEL statement.
- Python supports four different numeric types: Int (signed integer), long (longer (can also represent octal and hex), float (floating point), complex (plural)
- Python's list of strings has 2 order of values: From left to right index default 0 starts, the maximum range is the length of the string 1; right-to-left index default-1 starts with the maximum range is the beginning of the string
- If you want to implement a string to get a string, you can use the variable [header subscript: tail subscript], you can intercept the corresponding string, where the subscript is starting from 0, can be positive or negative, subscript can be null to take the head or tail.
- When using a colon-delimited string, Python returns a new object that contains the contiguous content identified with the offset, and the beginning of the left contains the bottom bounds. The maximum range that is taken does not include the upper boundary.
- The plus sign (+) is a string join operator, and an asterisk (*) is a repeating operation.
- The list is the most frequently used data type in Python. A list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, and strings that can even contain lists (that is, nesting). The list is identified by [], which is the most common type of composite data for Python.
- A tuple is another data type, similar to a list. The tuple is identified with a "()". The inner elements are separated by commas. However, tuples cannot be assigned two times, which is equivalent to a read-only list.
- The Dictionary (dictionary) is the most flexible built-in data structure type in Python, except for lists. A list is an ordered combination of objects, and a dictionary is a collection of unordered objects. The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets. The dictionary is identified with "{}". A dictionary consists of an index (key) and a value corresponding to it.
- Sometimes, we need to convert the data-built type into the data type, and you just need to use the data type as the function name.
- * * Power-Returns the Y power of X
- Divide-Returns the integer part of the quotient
- Note: In python2.x, integers can be derived only by integer except integers. If you want to get a fractional part, change one of the numbers to a floating-point number. python3.x, you get the fractional part.
- **= Power assignment operator C **= A is equivalent to C = c * * A
- = Take divisible assignment operator C//= A is equivalent to C = c//A
- and X and Y Boolean "and"-if x is False,x and y returns FALSE, otherwise it returns the computed value of Y. e.g. (A and B) returns 20.
- or X or y boolean "or"-if x is 0, it returns the value of x, otherwise it returns the computed value of Y. e.g. (A or B) returns 10.
- In if the value found in the specified sequence returns TRUE, False is returned. x in the y sequence, if X returns True in the y sequence.
- Not if no value is found in the specified sequence returns True, otherwise False is returned. X is not in the Y sequence if x does not return True in the y sequence.
- The identity operator is used to compare the storage units of two objects. NOTE: the ID () function is used to get the object memory address.
- IS is to determine whether two identifiers are referenced from an object x is Y, similar to ID (x) = = ID (y), and returns True if the reference is the same object, otherwise False
- Is isn't is to determine whether two identifiers are referenced from a different object x is not y, similar to ID (a)! = ID (b). Returns True if the reference is not the same object, otherwise False is returned.
- IS and = = is used to determine whether the two variables refer to the same object, = = is used to determine whether the value of the reference variable is equal.
- Where the "judging condition" is established (not 0), the following statements are executed, and the execution content can be multiple lines, in order to be indented to differentiate the same range.
- Since Python does not support switch statements, multiple criteria can be judged by elif.
- You can also use the IF condition to judge the statement on the same line position
- The judging condition can be any expression, and any value other than 0, or non-null (NULL), is true.
- While ... else executes an ELSE statement block when the loop condition is false
- Another way of performing a loop is by indexing
- In Python, for ... else means that the statement in for is no different from normal, while the statement in else is executed when the loop is executed normally (that is, for not breaking out by break), while ... else is the same.
- The Python Pass is an empty statement in order to maintain the integrity of the program structure. Pass does not do anything, generally used as a placeholder statement.
- The Python Number data type is used to store numeric values. The data type is not allowed to change, which means that if you change the value of the Number data type, the memory space will be redistributed.
- You can also use the DEL statement to delete some number object references.
- You can delete single or multiple objects by using the DEL statement
- Python supports four different numeric types: integer (Int), long Integer (long integers), float (floating point real values), complex number (complex numbers)
- Python uses "L" to display the long integer type.
- The Ceil function returns the number of integers that are entered. It cannot be accessed directly and requires the import math module to invoke the method through a static object.
- The floor function returns the lower integer of the number.
- The Max function returns the maximum value for a given parameter, which can be a sequence. The Min function returns the minimum value.
- The choice function returns a list of the random items of a tuple or string. Import random is required.
- The Randrange function returns a random number in the specified increment cardinality collection, with the base default value of 1.
- The random function returns a randomly real number, which is within the range of [0, 1).
- The shuffle function randomly sorts all elements of a sequence.
- The uniform function randomly generates the next real number, which is within the range of [x, Y].
The basic Python tutorial for learning notes