Learning python- Day 3 (Morning)

 Watching tutorial: Python Tutorial 6


I learnt about Lists today! These are amazing

In python I can now work with multiple values and string in a list.

There are awesome modifications that can be done with a list in python

  • Integer list: myList = [2, 3, 4, 5, 6, 80]
  • Float list: myListF = [2.3, 5.67, 8.54, 76.4]
  • String list: myListS = ['Hello', 'World', 'This', 'Is', 'Saad']
  • Hybrid list (Where I can have difference data types in same list): 
    myListH = [56, 'Hello', 76.43]
I can edit the lists by following these commands:

            list()

    Converts an object into a list.
    [] list comprehensions
    Returns a list based on existing iterables.
    literal syntax
    Initializes a new instance of the list type.

    Methods

    Adding Elements

    insert
    Inserts an item at a given position.
    append
    Adds an item to the end of the list.
    extend
    Extends the list by appending all the items from the iterable.

    Deleting

    remove
    Removes the first item from the list which matches the specified value.
    pop
    Removes and returns the item at the specified index.

    Information

    index
    Returns the index of the first occurrence of the specified list item.
    count
    Returns the number of times the specified item appears in the list.

    Modifying

    sort
    Sorts the list in place.
    reverse
    Reverses the elements of the list, in place.

    Functions

    len
    Returns an int type specifying number of elements in the collection.
    min
    Returns the smallest item from a collection.
    max
    Returns the largest item in an iterable or the largest of two or more arguments.
    cmp
    Compares two objects and returns an integer according to the outcome.
    sum
    Returns a total of the items contained in the iterable object.
    sorted
    Returns a sorted list from the iterable.
    reversed
    Returns a reverse iterator over a sequence.
    all
    Returns a Boolean value that indicates whether the collection contains only values that evaluate to True.
    any
    Returns a Boolean value that indicates whether the collection contains any values that evaluate to True.
    enumerate
    Returns an enumerate object.
    zip
    Returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.

    Operators

    [] (index operator)
    Gives access to a sequence’s element.
    [::] (slicing)
    Gives access to a specified range of sequence’s elements.
    + (concatenation)
    Returns a concatenation of two sequences.
    * (multiple concatenation)
    Returns a sequence self-concatenated specified amount of times.

Comments

Popular posts from this blog

Apple iPad Air (2022) Specifications and Review in 2023

17-year-old suspect in fatal stabbing at Taylor Swift-themed dance event ID’d

Exercise vs Diet