Python full stack (a) the basis of the basic data types 3

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/CUFEECR/article/details/102692058

First, several concepts

1. Expressions

Expression, a combination of numbers, operators, digital packet symbols (in parentheses), the free variables to variables and constraints can be obtained in the ball arrangement method meaningful value.
In plain words, the expression is something similar to a mathematical formula.
Expression does not affect the program.

2. Statement

Statement is self-contained on a grammatical unit, which consists of a word or group of words on a grammar associated.
The program will have an impact statement.

3. Program

Program is a one of the statements and expressions consisting of a one.

4. Functions

Function is designed to complete a specific function of the statement.
Form:xxx() .
Parameters : parameter function may not be added, may be added to one or more parameters, if a plurality of parameters, application "," separated.
Return value : Not all functions return a value.
Classification Function:
built-in functions of: providing by the Python interpreter can be directly used;
custom function : their function is to be defined as needed.

Second, the identifier

The Python language keywords, identifiers, 8 of the comment, and the numerical variables, operators, statements, functions, and so on sequence.

1. Keyword

Python own use, we can no longer define your own terms of use.
Can be executed in the console import keyword, then execute keyword.kwlistview Python keywords.

2. Identifier

Some developers symbol name in the custom program, such as variable names, class names, function names.

composition:

26 by the letters (case), 0-9, symbols _ $ and so on.

rule:

(1) The identifier may contain letters, numbers, _, but do not use digital beginning, e.g. name1, name _, _ name and the like;
(2) reserved words and keywords can not be used as an identifier.

naming method:

Nomenclature: See name meaning knowledge.
Hump nomenclature:
small hump : the first word beginning with a lowercase letter, word behind the first letter capitalized, such as myName, aDog;
large hump : the first letter of each word capitalized, such as FirstName, LastName;
Underline : underline to connect the two there are two meanings of the word, such as get_url, buffer_name.

Third, integer and fractional

1. integer

I.e. integer, as a = 1, b = 2, are int.
※ value stored computer is not infinite, a certain range;
※ large number of encounters, several intervals may be divided by an underscore _ as 123_456_789 like.

2. decimals

That float, such as a = 1.2, b = 0.09.
※ float is erroneous, calculated as Python 0.1 + 0.2 = .30000000000000004, rather than 0.3, because the computer operator with a binary number, is input in Python is a decimal number, the decimal in Python runtime an error results when converted to binary, so that the calculated errors.

Fourth, boolean, and null

1. Boolean

Only two Boolean values True and False , which are mostly used for logical judgment.
※ Boolean value that actually belong to integer, True is equivalent to 1, False is equivalent to 0.

2. null

That is None, is constant, data indicating a null value.

Fifth, string, and escape character

1. String

String is a string of characters from the characters, numbers, underscores, such as 'Hello', "World".
※ string comprising a single or double quotes, but single or double quotation marks must be used in pairs, but can not mix, and are not nested between the same marks.
※ may type()function to detect the type of a character string.

2. escape character

I.e., "\", meaning that the individual characters appearing in Python disappears, so that the first character escape sequence of characters having a different semantics of the sequence of characters appear alone.
\ 'Represents'
\ "represents"
\ T for a tab Tab
\ represents n-newline
\ backslash indicates
※ may add the letter 'r' have the meaning it had before the most string.

Sixth, a long string

For longer strings, after each line backslash \ make a string of different rows;
for a string of multiple rows, indicated by triple quotes required, this can wrap, while retaining the string format,
Such as

'''ascii(object)
As repr(), return a string containing a printable representation of 
an object, but escape the non-ASCII characters in the string returned 
by repr() using \x, \u or \U escapes. 
This generates a string similar to that returned by repr() in Python 2.
'''

That will keep the format string in the document and wraps.

# Seven, format string

A way to fight the string:

As can be spliced between string and string print('s = +s).
Type conversion may be performed, such as the implementation 6+str('6'), the output will be 12.

Embodiment a plurality of two parameters:

Pass multiple parameters, such as print('s =',s).

Three ways placeholder

String can be specified in the placeholder when creating a string.
Character% s
% d integers

e.g. print('I love %s' % 'Python'), print('I love %s and %s' % ('Python','Java')).
Note: must be accounted for and the median number of arguments behind the same, otherwise it will error.

Four ways "new" format string

s='Python'
print('I love {0}'.format(s))

Embodiment five string interpolation / f-Strings

s1='Python'
s2='Java
print(f'I love {s1} and {s2}')

※ For more information about the usage string, reference https://blog.csdn.net/ning13481193737/article/details/80948501 .

Eight other string operations

1. String length

With len()function.

2. String operations

Use s*20to print the string s 20 ed.

3. string contains

In use to determine whether a character string in another string, such as the use a in bto determine whether a b,

4. seeking the maximum and minimum

Use max()the summin()

The characters in the ASCII decimal values ​​request table

With the ord () function
print ( 'A')

6. Split string

With split () function returns a list of
such

s='I love Python'
s.split(' ')

7. The string concatenation

Using join () method, such as'_'.join(s)

8. strips spaces

space strip () to remove the left and right sides of the character of
the lstrip () to remove the space character to the left of
rstip () to remove the character space to the right
as

s=' I love Python '
print(s.strip())
print(s.lstrip())
print(s.rstrip())

9. The case of the string

upper () all uppercase
lower () all lowercase
capitialize () capitalized
isupper () to determine whether capital
islower () to determine whether lowercase

s='I love Python'
print(s.upper())
print(s.capitialize())
print(s.islower())

Nine, variable

1. When did the definition of variables:

When the data is uncertain, the need for data storage, it is necessary to define a variable to store complete.

2. What is variable

Is a variable region of the computer's memory, the values stored within a predetermined range.
※ value can be changed, simply, variable data is to take the name;
※ At the same time, variable names must follow the naming rules for identifiers;
※ by id()check address different variables stored in memory to;
equal to two variables and two variables are the same object are two different concepts.

3. Variable operation

a=10
b=4
print(a+b)

Summary: As long as containing floating-point arithmetic in the process, then the return is a floating-point number.

Guess you like

Origin blog.csdn.net/CUFEECR/article/details/102692058