Python: single colon vs double colon

前端 未结 5 1324
醉梦人生
醉梦人生 2020-12-31 15:05

What is the difference between single and double colon in this situation? data[0:,4] vs data[0::,4]

women_only_stats = data[0::,4]         


        
5条回答
  •  难免孤独
    2020-12-31 15:27

    In your case data is

    data = ['1' '0' '3' 'Braund, Mr. Owen Harris' 'male' '22' '1' '0' 'A/5 21171' '7.25' '' 'S']
    

    So it is equal to

    data = ['103Br.............7.25S']
    

    In this sitation there is only single item in list so data[0::4] or data[0:4] doesn't impact any thing.

    If you try this it will clear your question/answer

    print data[0][0::4]
    print data[0][0:4] 
    

    It works like

    data[start:end:step]
    

    So it behaves as usual if your step size is less then data length.

提交回复
热议问题