On the Advanced Python's built-in method

Ordered or disordered and variable or unchangeable

Ordered: an index of disorder: None Index

Variable: variable value changed, id immutable same: variable value becomes, id becomes

Built-in digital type method

Plastic

1. Role

Description of age, id, height

2. Define the way

x=10
x=int('10')

3. built-in method

No built-in method, only the arithmetic and compare operations

4. The presence of a plurality of values ​​or value

A value

5. orderly or disorderly

This statement is not shaping

6. The variable or invariable

Shaping is immutable

Float

1. Role

Description salaries and other

2. Define the way

x=1.1
x=float('1.1')

3. built-in way

And plastic as there is no built-in method, only the arithmetic and logic operations

4. The presence of a plurality of values ​​or value

And as there is only one integer value

5. orderly or disorderly

This is not to say

6. The variable or invariable

As with integers are immutable

String type built-in method

1. Role

Describe the nature of things, such as the person's name, a single loving, address, country, saying, etc., can effectively represent a constant sequence of characters, based on the Unicode international character sets.

2. Definitions

name='tim'
s=str(1.2)

3. built-in way

1. Press the index value

name='tim'
print(f'索引为1: {name[1]}')
print(f'索引0: {name[0]}')

2. Section (care regardless of the end, step)

name='tim'
print(f'切片1-最后: {name[1:]}')

3. length

name='tim'
print(len(name))

4. Members and not in operation

name='tim'
print('tim'in name)#判断tim是否在字符串内

5. Remove the blank

name='  tim'
print(name.strip)

6. Segmentation

info = 'nick:male:19'
info_list = info.split(':')
print(f'info_list1:{info_list1}')

7. cycle

name='tim'
for i in name:
    print(i)

8. left and right blank blank

name='  **tim**  '
print(f'左对齐:{name.lstrip('*')}')
print(f'右对齐:{name.rstrip('*')}')

9. uppercase and lowercase

name='Tim'
print(name.lower())#小写
print(name.upper())#大写

10. begin with ... and ending with ...

name='tim'
print(name.startswith('t'))#以...开始
print(name.endswith('m'))#以...结尾

11. The right cutting

name='tim'
print(name.rsplit('i'))

12. The United

name = ['tim', 'male', '19']
print(name.join(name))

13. Alternative

name='tim'
print(name.replace('name','NAME'))

14 is a number

name='tim'
print(name.isdigit())

15. Find

name='tim'
print(name.find('i'))

16. Index

name='tim'
print(name.index('i'))

17. The Center

name='tim'
print(name.center(9))

18. Left

name='tim'
print(ljust(50,'*'))

19. Align Right

name='tim'
print(rjust(50,'*'))

20. capitalized

name='tim'
print(name.captalize())

21. invert case

name='Tim'
print(name.swapcase())

22. Title

name='tim'
print(name.title())

4. The presence of a plurality of values ​​or value

As with digital type has only one value

5. orderly or disorderly

String is indexed, it is ordered

6. The variable or invariable

And digital is as immutable

As with digital type is variable

Guess you like

Origin www.cnblogs.com/MrYang161/p/11290788.html