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)

Modulus % - Using the % symbol you can get the remainder.

+=1 - this will add one to a variable, for instance -
number = 1 
while number <= 10:
print(f"number is {number}")
number += 1 
In this example if the +=1 was not included this would loop forever, this is because the variable number would always be less than 10, but because the "number += 1" was included each time the number loops it adds one until it reaches ten then the program will stop as the variable number = 10. 

Comments

Popular posts from this blog

Python Crash Course Chapter 1-2! #1

I PASSED! Cisco CCNA 200-301! Experience & Where I'm going from here!

Python Notes #6 Functions