Skip to main content

Posts

Showing posts from March, 2023

Dynamic Lists

 Dynamic Lists  Dynamic lists are ways of using a blank list and adding or removing items to it as we go                Blank lists  EXAMPLE :   MYAGENDA = []  Append a list .append will let us add whatever is in () to the list.  EXAMPLE:  myAgenda = [] def printList():     for item in myAgenda:     print(item) while True:   item = input("What's next on the Agenda?: ")   myAgenda.append(item)   printList()  Removing Items from a List how using  .remove will remove what is inside the (). EXAMPLE: myAgenda = [] def printList():   print()    for item in myAgenda:     print(item)   print()  while True:   menu = input("add or remove?: ")   if menu == "add":     item = input("What's next on the Agenda?: ")     myAgenda.append(item)   elif menu == "remove":     item = input("What do you want to remove?: ")     myAgenda.remove(item)   printList()

LISTS

 LISTS As far as Python is concerned, this is a list. Notice we start counting the first item at 0 (instead of 1) Any piece of data from any data type can go into a list. We can extract, remove, or change lists  EXAMPLE: timetable = ["Computer Science", "Math", "English", "Art", "Sport"] print(timetable[1])  Lists and Loops: EXAMPLE: timetable = ["Computer Science", "Math", "English", "Art", "Watch TV"] for lesson in timetable:   print(lesson) 

ALL ABOUT f- string

  f-strings f-strings (format strings) are the best way to combine variables and text together.  EXAMPLE : name = "Katie" age = "28" pronouns = "she/her" print("This is {}, using {} pronouns, and is {} years old.".format(name, pronouns, age))  Local Variables : EXAMPLE name = "Katie" age = "28" pronouns = "she/her" print("This is {name}, using {pronouns} pronouns, and is {age} years old. Hello, {name}. How are you? Have you been having a great {age} years so far".format(name=name, pronouns=pronouns, age=age))  The Power of f... EXAMPLE: name = "Katie" age = "28" pronouns = "she/her" response = f"This is {name}, using {pronouns} pronouns, and is {age} years old. Hello, {name}. How are you? Have you been having a great {age} years so far" print(response) Alignment: left = <, right = >, center = ^  EXAMPLE: for i in range(1, 31):   print(f"Day {i: <2} of 30

MORE ABOUT print

 end  EXAMPLE:  for i in range(0, 100):   print(i, end=" ") NEW LINE : #new line for i in range(0, 100):   print(i, end="\n")                                                 TAB INDENT: #tab indent for i in range(0, 100):   print(i, end="\t")                                         VERTICAL TAB: #vertical tab for i in range(0, 100):   print(i, end="\v") sep  print("If you put ", "\033[33m", "nothing as the ", "\033[35m", "end character ", "\033[32m", "then you don't ", "\033[0m", "get odd gaps ", sep="")  Cursor EXAMPLE import os, time print('\033[?25l', end="") for i in range(1, 101):   print(i)   time.sleep(0.2)   os.system("clear")