common data types for Python
A= 10 Integer type
b=10.0 floating Point type
c= "Hello" string
D=true Boolean True/fales
Application method
Integer:
A=1
Print (a)
Floating point number:
b=2.0
Print (b)
Boolean:
Print (B>a)
True
Print (B<a)
Fales
String:
C= "Hello,tom"
Find:
Print c.find (' h ')
return subscript
0
Print c.find (' O ')
4
Print C.find (' W ')
Cannot find return
-1
Replace
Print C.replace (' Tom ', ' Lili ')
Hello,lili
Segmentation
Print C.split (', ');
Ask delimiters with commas
"Hello", "Tom"
Integrated integration
C= ":"
d= ("Hello", "Tom")
Print C.join (d);
Hello:tom
Front and back spaces
C= "Hello,tom"
Print C.strip ();
Hello,tom
String formatting
C= "Hello,tom"
{0}.format (c)
Hello,tom
{0} {1}.format ("Hello", "Tom")
Hello, Tom.
{1} {0}.format ("Hello", "Tom")
Tom Hello
List list[]
Lists can put any string, number, letter, the list of elements without any association, the list punch exists subscript, default starting from 0
Like what:
conn=["1", "1.11", "Hello", "True"] this is a list
List of commonly used processing methods:
C=conn.append ("Lili") add an element at the end of the list
Print (c)
1,1.11,hello,true,lili
C=conn.pop () deletes an element at the end of the list
Print (c)
1,1.11,hello
Conn.index () returns the subscript of an element
Print Conn.index ("Hello")
2
Conn.remove () Delete elements based on subscript
Ditto
Conn.sort () sort
Conn.reverse () Reverse Sort
Conn. [:] Shard, front open, rear closed
A=conn[1:3]
B=conn[:3]
C=conn[2:]
D=CONN[:-1]
Print a
[1.11,hello]
Print B
[1,1.11,hello]
Print C
[Hello,true]
Print D
[1,1.11,hello]
Getting Started with Python (ii) Processing of strings