string-indexing&slicing

Run Settings
LanguagePython
Language Version
Run Command
# we access a piece of string using a index. # since every char/element inside a sting is stored in memory bit by bit. # we can say we are asking python for the specific bit by giving python a token number in the form of a index. selfish = "me me me" # 012347 # [start:stop] print(selfish[0]) print(selfish[-1]) # [start:stop:step] step over a few elements. selfish_2 = '01234567' print(selfish_2[0:6]) # upto number 5 # start from the beginning and end at a specific point print(selfish_2[:5]) # start from a specific point and end at the end of the sequence print(selfish_2[2:]) # To jump alternating numbers in between print(selfish_2[::2]) # To reverse a sequence print(selfish_2[::-1])
Editor Settings
Theme
Key bindings
Full width
Lines