slicing strings in python

Hmm I was looking for slicing stings in python,
it is very simple

x[start:end] # items from your start till your end value
x[start:]    # items from start your value to the end
x[:end]      # all items from the beginning to your defined end
x[:]         # and just a copy of the whole array


x = "Hello World!" # we have 12 characters so 0:12
print(x)           # shows all 
print(x[0:12])     # shows all as well
print(x[:])        # shows all
print(x[2:10])     # shows llo Worl

Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.