Python Basic Knowledge Summary (1) __python

Source: Internet
Author: User

Recently there are frequent use of Python to deal with data and implementation algorithms, but unfortunately their Python foundation is not solid enough, there are many knowledge points need to temporarily check. Today, spend one night reviewing the Python basics for later review. 1.Python data type:

(1) tuple (Tuple) & list : Tuples and lists are sequences of Python data types in sequence. such as (1, ' abc ', 0.5) is a tuple containing three elements. [1, ' abc ', 0.5] is a typical list. You can look up an element in a tuple or list by index.
The difference : Python allows the user to modify the data in the list while accessing it, but not the tuple.
(2) dictionary (Dictionary): A typical dictionary in Python contains multiple sets of keys (key): value pairs, such as {1: ' 1 ', ' abc ': 0,1,0.4:80}. The keys in the dictionary are unique. 2.Python Data Operations

(1) arithmetic operations (arithmetic Operators): Python commonly used arithmetic operators are: addition (+), subtraction (-), multiplication (), Division (/), modulo (%) and power exponent (*) operations.
(2) comparison operation (Comparison Operators): In Python, a comparison operation returns the result of a Boolean type, that is, true or False.
(3) assignment Operation (Assignment Operators): Once the tuple is initialized, its internal elements cannot be changed.
(4) logical Operation (Logical Operators): There are logical operators in Python with (and), or (or), non (not) three. The data type and return value involved in the operation are all Boolean values.
(5) member operations (Membership Operators): primarily for metadata types such as tuples, lists, and dictionaries. You can use the in operator to ask whether a tuple appears in a tuple or list, or whether a key (key) exists in the dictionary. If t = [1, ' abc ', 0.5], let the input 0.5 in T return true. 3.Python Process Control

(1) Branch statement (IF): You can choose to execute a portion of the code depending on the situation.
The common syntax results are as follows:
If Boolean value/Expression:
"tab" Execution branch 1 ...
Else:
"tab" Execution branch 2 ...
Examples are as follows:

(2) Circular control (for): You can recycle some code, often with the help of traversal to complete the control of the loop statement. The common traversal syntax is as follows:
For temporary variable in can traverse data structure (list, tuple, dictionary):
tab to execute statements (you can have multiple lines, all require tab indents) ...
Examples are as follows:
4.Python function (module) design

In the design aspect of a function (module), you can provide the function with the necessary parameter input, and get the desired return value from the function (module). Python uses def keywords to define a function (module), as shown in the following example:
5.Python Programming Library (package) import

Python, as an open-source ecosystem, contains many libraries and packages (Package). The base library has NumPy,scipy and matplotlibthat facilitate vectors, matrices and complex scientific computations, as well as the pandasof fast analysis and processing of data. Scikit-learnthat contains a large number of classical machine learning models. In addition, there are some recently popular professional libraries, such as NLTKfor natural language processing, word vector Word2vecfor computing word similarity, classical integrated classifier model Xgboost, Google's latest in-depth learning framework TensorFlow.

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.