Ad

Reversing the list with a slice.

Code
Diff
  • def print_String(List):
        
        # Printing the index of a string in the list.
        lst = ['double', 'switch', 'off', 'on', 'jump']
        print(lst.index('double'))
        
        # Reversing the items in the list
        print('Reversed List:', lst[::-1])
    • def print_String(List):
    • # Printing the index of a string in the list.
    • List = ['double', 'switch', 'off', 'on', 'jump']
    • index = List.index('double')
    • print (index)
    • lst = ['double', 'switch', 'off', 'on', 'jump']
    • print(lst.index('double'))
    • # Reversing the items in the list
    • List.reverse()
    • print ('Reversed List:', List)
    • print('Reversed List:', lst[::-1])
Code
Diff
  • def print_statements():
        # Printing lines of code:
        print("Hello Mark!","This is my first python script.","Python will be fun to learn!","I am not at COGS","I am at home in my jammies.", sep="\n")
    • def print_statements():
    • # Printing lines of code:
    • print("Hello Mark!","This is my first python script.","Python will be fun to learn!","I am not at COGS","I am at home in my jammies.")
    • print("Hello Mark!","This is my first python script.","Python will be fun to learn!","I am not at COGS","I am at home in my jammies.", sep="\n")