!# code (Hash Bang Code)

4 supporters

New post! Slicing Arrays and Strings Using The Colon Operator In Python

Sep 06, 2021

Strings and arrays can be manipulated in a number of ways in python. Splitting a string or an array into sections can be done using the section slicing that is built into the core python syntax and uses the colon (:) symbol.

Generating a simple array in python is straightforward, the following creates an array of 9 elements.

anArray =[1,2,3,4,5,6,7,8,9]

To grab a particular element of the array you can use the simplest section slicing syntax. The number in the square brackets represents the position of the item to be returned. Remember that the counting starts at 0, so using 1 will return the item from the "second" position.

Read more here: https://www.hashbangcode.com/article/slicing-arrays-and-strings-using-colon-operator-python

Enjoy this post?
Buy !# code (Hash Bang Code) a coffee
Sign up or Log in to leave a comment.