LATTEOTW

  • Range

    From Python official document:

    class range(stop)

    class range(start, stop[, step])

    Rather than being a function, range is actually an immutable sequence type, as documented in Ranges and Sequence Types >— list, tuple, range.

    Range is a little bit different than all other built-in functions. It’s essential a data type that’s built-in in Python. More specifically, it shares the same feature of list and tuple - it’s sequential. Let’s introduce some features and usage of range.

    • Start is inclusive and stop is exclusive

      1
      2
      for i in range(1, 3, 1):
      print(i)

      This will print:

      1
      2
      1
      2
  • List Concatenation

    There are two ways two concatenate a list with another. One is to use + to concatenate a list. Another way is to use extend() function to concatenate

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # Use + to concatenation a list
    A = ['a', 'p', 'p', 'l', 'e']
    B = ['b', 'a', 'n', 'a', 'n', 'a']
    C = A + B
    print(C) # ['a', 'p', 'p', 'l', 'e', 'b', 'a', 'n', 'a', 'n', 'a']

    # Use extend() function to concatenate
    A.extend(B)
    print(A) # ['a', 'p', 'p', 'l', 'e', 'b', 'a', 'n', 'a', 'n', 'a']

Copyright © 2020 LATTEOTW

Use Material X as theme. Total visits times