Gizmotronn / python-learning

Learning about python for future projects
https://github.com/acord-robotics/python-learning
4 stars 3 forks source link

Python Programming for Beginners Udemy Course #6

Closed Gizmotronn closed 4 years ago

Gizmotronn commented 4 years ago

Course link: https://www.udemy.com/course/python-programming-beginners/

Gizmotronn commented 4 years ago

Section 8 - Tuples

# Tuple - a collection of immutable objects (can't be changed - e.g. d.o.b). 'tuple' object does not support item assignment
tupleName = (object1, object2) # sets the values of the objects in the tuple "tupleName" to "object1"  & "object2"
tupleName # prints the values of the tuple "tupleName" to the console

# Accessing values in a tuple
tupleName[0] # returns "object1"

# Deleting tuples
del(tupleName) # Deletes the tuple
tupleName = (object1, object2) # Creates tupleName again!

# Tuple exercises
# Easy -  Write a program to create a tuple of 4 elements
tuple4 = (object11, object22, object33, object4)

# Medium - convert this tuple ("tuple4") to a list
list(tuple4)

# Hard - Now delete the first element in this list and convert it back to tuple
tuple4.remove(object11)
tuple(tuple4)
Gizmotronn commented 4 years ago

Section 7 - Lists

# Lists
# https://www.udemy.com/course/python-programming-beginners/learn/lecture/6727846#overview
# listName = [object1, object3, object4]
listName = ["object1", "object2", "object11"] # object1 has an index value of 0, object2 has an index value of 1
listName # prints the values in the "list" with the name "listName"

# Accessing values in lists
listName[1] # prints the second object in the list "listName", in this case "object2"

# Replacing/modifying lists
listName[1] = "object7" # Replaces the value of the second value in list "listName" with "object7"
listName # Prints the values assigned to the list "listName" to the console

# List Operations

# Append operation - add an object to the end of the list
listName.append("object99") # Adds "object99" to the end of the list "listName"

# Insert operation
listName.insert(1, "object66") # Addes "object66" to the index value of 1 (2 overall object) to the list "listName"

# Remove Operation
listName.remove("object99") # Removes the object "object99" from the list "listName"

# Sort Operation
listName.sort() # Arranges the list "listName" in alphabetical order

# Reverse Operation
listName.reverse # Reverses the order of the list "listName"

# Pop Operation
listName.pop() # Removes the last object in the list "listName" and prints it to the console

# Exercises

# Easy - Write a program to create a list of 5 elements
myList = ["This", "list", "contains", "five", "elements"]

# Medium - Update the value at 3rd element of the list
myList[3] = "does contain"

# Hard - Create another list of 3 elements. Now create a final result as a concatenation of the first two lists
myListTwo = ["3", "elements", "are here"]
myListTogether = myListTwo + myList
Gizmotronn commented 4 years ago

This issue will be temporarily closed. While the course was good, I am getting more out of issue #7