Python- string variable +

String
escape character
format
built-in functions (trailing)
escape character
with a special method is not convenient to write the contents of a series of shows, such as carriage returns, line feed key, the backspace key
by backslash character, Once the backslash appears in the string, the backslash fire behind a few characters represent not the original meaning, had escaped
in the string, once there was going backslash extra care may be provided by escape character appears
different systems have different representations of the LF Action
Windows: \ the n-
Linux: \ r \ the n-

# If you want shows Let's go to 
# 1 can use nested quotes, i.e., the outer double quotes 
# 2. The escape character 
S = "Let's go" 
Print (S) 

# \ '==' 
SS = 'Let \ 'S Go' 
Print (SS) 

# \\ = \ 
sss = "C: \\ User" 
Print (sss) 

# carriage return 
S1 = "Love the I \ R & lt \ n-HHH" 
Print (S1)

  

String format
string printed or filled in a format
formatted by the two methods
using the percent (%)
using the format function

Percent using format
in the string, using a special meaning expressed in%, indicates the character format
% d: an integer should here be placed in
% s: here indicates a character string to be placed

 

= S "the I Love% s" 
# underside of the print, as a% s directly print out the contents of the string 
Print (S) 

Print ( "the I Love% s"% "HHH") 

Print (% S "HHHHH") 

S = "% D years the I AM Old" 
# watching the distinction between the following sentences and the result 
Print (S) 
Print (18 is% S) 

S = "% S the I AM, AM I% D years Old" 
Print (S) 
# Note the following error cause expression 
# If the string, by some placeholder placeholder must be replaced by a few actual content, or a do not 
#Print (% S "tulingxueyuan") 

# If multiple placeholder appears character, the corresponding content needs parentheses 
print (s% ( "tulingxueyuan" , 18))

  

format function format string
format format function directly with
the recommended use of this method
in use, and in {}:% instead of number, followed by the completion of format parameters

s = "I love {}".format("LiXiaojing")
print(s)

s = "Yes, i am {1} years old, I love {0} and i am {1} years old".format("Tulingxueyuan", 18)
print(s)

  

None
represents nothing
if the function does not return a value, you can return None
to occupy the position
for contacting the variable binding

Expression
of one or several numbers or a combination of variables and operators into a line of code
typically returns a result

Operator
after the change by the value of one or more new value calculation process is called
symbols called operators for calculating
operator Category:
arithmetic operators
comparison or relational operators
assignment operators
Logical Operators
Bitwise
member operator
identity operator

Arithmetic operators
perform arithmetic symbols
python not increment decrement operators

# + - normal arithmetic operators with identical 
A + = 3-2. 9 
Print (A) 
# multiplication (*) are replaced with asterisks 
A = *. 4. 9 
Print (A) 
# number except slash (/) in place of 
# python3.x in Python2.x and, in addition to number (/) may be inconsistent results, here to subject series 3 
A = 9/4 
Print (A) 


#% remainder calculation 
# dividing two numbers should quotient more than the number 
#% only get the remainder 
A = 9% 4 
Print (A) 

# // represents taking business operations, also known floors in addition to 
A = 9 // 4 
Print (A) 

# ** represents power operation 
a = 9 ** . 4 
Print (A) 

A =. 3. 3 ** 
Print (A)

  

Comparison Operators

Operator on two variables or a value comparison
result of the comparison is a Boolean value, i.e., True / False

# == equal number 
A =. 4. 3 ** 
# The following statement is executed book order is 
# 1, is calculated == 80 A 
# b, 2. Put the result 
b = 80 A == 
Print (b) 


#! = Not equal 
Print (. 9! =. 8) 

#> is greater than 
# <smaller than 
#> = greater than or equal 
# <= less than or equal

  

Assignment Operators

# =, Assignment 
A = 0 
C = A =. 4 

# + = is the abbreviation, 
A = 0 
A + =. 7 # Abbreviation a = a + 7 of 
Print (A) 


# of all mathematical operators are abbreviations 
# - =, × =, / =, // = ,% =, ** =, all abbreviations

  

Logical operators
Boolean value calculated symbols
and logical AND
or logical or
not logical not
python logical operation exclusive OR operation no
operation rule:
and considered as multiplication, addition or seen,
True regarded as 1, False seen 0
then the logical operation can be converted into integer math
final result is 0 if compared to False, True otherwise
short problem logical operations
, calculated according to the formula calculation order logic operations, can be determined once the future value of the entire formula is not evaluated directly back

Case # logical operator 
A = True 
B = False 
C = True 

# is equivalent to the following equation. 1 * 0 = + D. 1 
D = A or B and C 
Print (D) 


D or A = B and A 
Print (D)

  

Case # logic operation shorting 

# following logical expression, a value must be True, the operation or the time, are not counted down the entire expression 
a = True or XXXXXXXXXXX 

# following expression, if the expression contains assignment xxx type, the result is difficult to expect 
# code sample (pseudocode) 
b = 0 
a = a or (b =. 9). 6 and 
# is assumed that the above expression if no syntax error 
# of the final value of b should not be 0. 9 
Print (B) 
Print (A)

  

Operational sign member
for detecting whether a particular variable is a member of another variable
in
Not in

# 案例
l = [1,2,3,4,5]
a = 7

b = a in l
print(b)

a = 4
print(a in l)

print(a not in l)

  

Identity operation
is: is used to detect whether the two variables are the same variable
syntax is IS var2 var1
IS not: the two variables are not the same variable

In fact, comparison of the allocated space is variable
in Python values between -5 to 255, assigned to the same space

a = 9
b = 9
print( a is b)

a = "I love "
b = "I love "
print( a is b)

  

Priority issues operators
always remember brackets with the highest priority
the priority table

** index (highest priority)
- Bitwise inversion, Unary plus and minus (the last two named method and @ + - @)
/% // multiply, divide, modulo, and take divisible
+ Add Subtract
> > << right, left operator
& bits 'the AND'
^ | bitwise
<= <>> = Comparison operators
<!> = == equality operator
=% = / = @ + = == * = * = assignment operator
is is not the identity of the operator
in not in member operator
not or and logical operators


Original: https: //blog.csdn.net/weixin_42394170/article/details/90300243

Guess you like

Origin www.cnblogs.com/qbdj/p/10956652.html