1. String:
Create a string in Python we can use quotation marks ' or '.
Python accesses substrings, you can use square brackets to intercept strings:
var= "Hello world!"
Var2= "Runover"
Print ("var[0]:", var[0])
Print ("Var2[1:5]:")
The above code performs as follows:
Var[0]:h
Var2[1:5]:unno
Of course Python can also update the string:
var above
Print ("Updated string:", VAR[:6]+VAR2)
Execute the code as follows:
Updated string: Hello Runover, thus we can see that the string can be intercepted.
2. Operators:
Python is easy for other languages, one of which is the string operator:
As String A=java B=python, there are
+ Character channeling Link: a+b output is Javapython
* Duplicate output string: A*2 output is also Javajava
[] Get the characters in a string by index: a[1] The output is E
[:] Intercepting part of a string: A[1:4] Output is AVA
In member operator (if the string contains the given character returns true): The output of H in a is 1 (1 is true,0 to flase)
The not in transverse is obviously the last inverse;
% format string: This is more complicated, we'll explain in more detail below
The most basic usage of% is to insert a value into a character that has the string format character%s:
Print ("My name%s this year%d years"% (' Ti Xiaodong ', 20)) The output is also my name Ti Xiaodong this year 20 years old
% and multiple letter combinations have different effects such as the following:
%c: Formatting characters and their ASC11
%d: Formatted integer
%u: Formatting unsigned integers
%o: Formatting octal
%x: Format 16-bit
%f: Formatting floating point
%p: Using 16-bit binary format variable address
Python
Python Learning Chapter 2nd