Posts

Showing posts from December, 2020

Python Notes #6 Functions

 Hi Everyone, Today I'm doing functions I have kept this as its own blog as this is a bit of a tougher topic and for my own memory I'd like to be able to find this easily if I ever had to review python notes. A function is a chunk of reusable code this means that the code can be created and then passed anywhere within the code later on. This is how a function works -  def name(first, last): print("Please enter name: ") print(f"Your name is: {first} {last}") name("Iain", "H") In this chunk of code I pass the parameters first & last within the function - from here I create a print statement asking for my name, notice how in the second print statement I am passing the parameters first and last (represented by the curly braces) and lastly I call the function name and define the values within the brackets - with the last statement now first will = 'Iain' and last will = 'H'. This code produces this output - Please enter

Python Notes #5 List, Tuple, Set, Dictionary, input, while

 Hi Everyone! Today I have another note dump I need to make up, these are taking me longer to post because im learning nearly all of this practically I would have to post my code then individually explain each chunk of code and that just takes to long.  List []  is a collection which is ordered and changeable. Allows duplicate members. Tuple ()  is a collection which is ordered and unchangeable. Allows duplicate members. Set {}  is a collection which is unordered and unindexed. No duplicate members. Dictionary {key:value}  is a collection which is unordered and changeable. No duplicate members. for *variable* in *already created variable*:     print("") input() - use to get input from user. When using this function the value will be stored as a STRING regardless if you enter a number, if you enter the value 7 the value will be stored as string "7". Example - enter_age = input() int() - converts a string variable to an integer. Example - enter_age = int(enter_age) M

Python Crash Course for loops! #4

 Hi Everyone, This is what I have been messing about with tonight, just doing loops over and over again!  for loops are made up of the variable and value: pizza = ["pep", "cheese", "donner"] for pizzas in pizza : print(f"I like {pizzas.upper()}") print(f"My fav type of pizza is {pizza[0]}") animals = ["Dog", "Cat", "Chicken"] for pets in animals: print(f"{pets} are my fav!") print(f"a {pets} would make a great pet") print("These animals are great!") In this code the value of pizzas is the variable and is getting assigned the value of pizza, the next statement is then indented and printed.