Dot notation string manipulation

前端 未结 5 1135
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 00:28

Is there a way to manipulate a string in Python using the following ways?

For any string that is stored in dot notation, for example:

s = \"classes.s         


        
5条回答
  •  囚心锁ツ
    2020-12-07 01:26

    if '.' in s, s.rpartition('.') finds last dot in s,
    and returns (before_last_dot, dot, after_last_dot):

    s = "classes.students.grades"
    s.rpartition('.')[0]
    

提交回复
热议问题