Python- aggregated basis

 

1, Python Introduction

Python is an interpreted, compiled, interactive, and object-oriented scripting language.
Compiled language: After compiling the code, compiled into a binary file, then the computer can be used to run.
Interpreted language: it is only when running compiled.
Scripting language: the language refers to only a single function.

Features: Easy to learn, easy to read
and elegant "," clear "," simple "

2, Python installation

Download: https: //www.python.org/downloads/windows/

Check the [Add Python 3.7 to PATH] is aimed at setting the path environment variable to find [python.exe]
if not checked, can be added manually.

 If not checked, can be added manually in the environment variable

 3, Integrated Development Environment (IDE)

Integrated development environment (IDE, Integrated Development Environment) is an application program for providing a development environment, typically including code editor, a compiler, a debugger, and the like graphical user interface tools. Integrated coding function, integrated analysis capabilities, compilation, debugging features such as software development services suite. All have this characteristic of software or software suite (group) can be called an integrated development environment.

4, a Python program

Direct enter code
print contents specified print ()
reads the external file

 

 

 5, input and output

 6 comments

A comment refers to the code function to mark text for explanation of the code, you can improve the readability of the code. Content annotation will be ignored Python interpreter. And it will not be reflected in the implementation of the results.
In Python, typically includes three types of annotations, each annotation is a single-line, multi-line comment and Chinese comments statements.

 Multi-line comments: python commonly used to document information module, and the like or a function add copyright class, function, also serve to explain the function of important information, parameters and the like.

 Chinese encoding declaration Note: If you use the specified type of Chinese character encoding encoding, need to add Chinese annotation statement at the beginning of the file

Format: # - * - coding: encoding - * - or # coding = coding
such as saving a file in UTF-8 encoding format

 7, the circulating branch (IF)

Python is not like most other languages ​​use "{}" The statement body, but to judge by indenting statement statement body, the default is indented 4 spaces

 If statement by "==" operator judgment equal, the "! =" Operator is determined not equal

 If statements can also use the "in" and "not in" to determine whether the string contains

  8, and the branch loop (the while)

While cycling is through a condition to control whether or not to continue the loop is repeated statement in
the format: while the conditional expression
   loop

 9, the circulating branch (for)

The for loop is a count cycle, typically used to traverse the sequence, and an iterative object elements, generally used in the case of known cycles.
Format: for the iteration variable in the object:
      the loop

 10, a list of

 Lists, tuples and dictionaries are the most common form used to store data. Following is a brief introduction:

Index: sequence all of the elements are numbered (from 0 increments) number of these elements is called an index.

A list of actions
print any element
print the last element
to modify any element
at the end of adding elements
to delete any element

 11, tuple

The list is immutable tuple, the tuple is [] instead of ()
tuples can not change, can not be completed sort tuples can not append and remove elements

 

 

Creating an array of tuples

Delete tuple

Modify connection tuple element

Tuples are immutable sequence, the individual elements can not be modified. But you may be reassigned to a tuple
contents must all be connected tuples

 

 12, dictionary

Dictionary '{}' indicated by braces, each element consists of a key value and a composition, a colon between the key and the value ':' separator, with different elements ',' separated.
Keys () returns a list of dictionary key, values () Returns the value of the dictionary list, items () will return all of the dictionary elements in a list. Pop () to delete an element dictionary by specifying key

 

 13, function

Function is widely used. For example, a print statement (), for input () function of the inputs, and generating a sequence of integer numbers range () function, Python custom functions may also be supported by some regular, repetitive code defined as a function achieve the purpose of write once called many times, can increase code reuse.

 14, classes and methods

Class is the core concept of object-oriented programming, is the carrier of the attributes and behavior of objects package, a class of entities other hand has the same properties and behavior of the class is called.
Everything in Python is an object, not just specific things called objects, strings, functions are also objects
calling the method: the method is called (this refers to the object method) method through the object point

 15, module calls

Modules, generally referred to as modules or libraries. In the actual development, it will inevitably use Python's standard modules and third-party libraries. If you want to achieve time-related features, you need to call the python standard modules of time. If you want to implement Web automated testing, you need to call third-party library Python Selenium.

 

Guess you like

Origin www.cnblogs.com/katyhudson/p/12462552.html