python basic data types and their special function command string -2-

1, the index, the subscript Get a character string (a character corresponding to the first number is 0)

1 a="abc"
2 b=a[2]
3 print(b)
4 
5 b=c

 

2, a character string obtaining section (left and right open and closed)

1 a="abcd"
2 b=a[0:3]
3 print(b)
4 
5 b=abc

 

3, get a few characters in the current string

1 a="abc"
2 b=len(a)
3 print(b)
4 
5 b=3

 

4, for circulation

1 a="abcde"
2 for  b  in  a :
3     print(b)
4     b=a
5         b
6         c
7         d
8         e

 

Guess you like

Origin www.cnblogs.com/chouchouzhu/p/10990991.html