Getting Started with Python (ii) Processing of strings

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.