python:python_snippets:w3_schools_python

This is an old revision of the document!


W3 Schools Python Course

"""
This is me running through a w3 python course to try and get stronger with python
"""
 
#here is a basic if else statement covering greater than and less than.
 
if 5 > 2:
    print ("5 is greater than 2")
 
if 5 < 2:
    print("5 is greater then 2")
else:
    print("2 is less than 5")
 
 
#Here is a complicated if else statement where integers are calculated before being changed to strings to be shown in a text string response
 
x = 5
y = 2
 
print(x)
print(y)
 
a = str(3)
b = int(4)
c = float(5)
 
print(type(a))
print(type(b))
print(type(c))
 
print (a,b,c)
 
d= 'lower case d'
D= 'upper case D'
 
print(d)
print(D)
 
if x > y:
    x = str(x)
    y =str(y)
    print(x + " is greater than "+ y)
 
if x < y:
    print (x + " is greater than "+ y)
else:
    x = str(x)
    y = str(y)
    print(y + " is Less than " + x)
 
 
"""
End of 5/9
Continue 
https://www.w3schools.com/python/python_variables_names.asp
Tomorrow
 
"""
 
 
#Many named variables, one of after the other.
 
name1,name2,name3 = "John","Lisa","jane"
 
print(name1,name2,name3)
 
 
#One string assigned to multiple variables.
 
x=y=z= "banana"
 
print(x,y,z)
 
#Unpacking a collection
 
fruits = ["apple","banana","grapes"]
 
x,y,z = fruits
 
print(x,y,z)
 
 
#concatenating string example
 
x = "Python "
y = "is "
z = "awesome"
 
print(x + y + z)
 
#printing two types together, like int and str
 
x = "python"
y= 5
 
print (x,y)
 
 
#global variables outside of a function can be used by all functions.
#variables inside of a function do not exist outside of the function
 
x = "awesome sauce"
 
def variabletest():
    x = "fantastic"
    print("Python is " + x)
 
 
print("Python is " + x)
 
variabletest()
 
 
#Use the global keyword to make a variable inside of a function usable outside of it.
 
def globalvariabletest():
    global y
    y = "I am a global variable"
    print(y)
 
globalvariabletest()
 
print(y)
 
#Here are the different data types for variables
a = str("hello world")
print(a)
 
a = int(50)
print(a)
 
a = float(20.6)
print(a)
 
a = complex(1j)
print(a)
 
a = list["a","b","c","d"]
print(a)
 
a = ('e','f','g','h')
print(a)
 
a = range(7)
print(a)
 
a = {"name":"jonathan","age":38}
print(a)
 
a = {"apple","banana","pie"}
print(a)
 
a = frozenset({"cherry","pineapple","pen"})
print(a)
 
a = bool(True)
print (a)
 
a = b"beatyourmeet"
print(a)
 
a = bytearray(20)
print(a)
 
a = memoryview(bytes(20))
print(a)
 
 
a = None
print(a)
 
 
"""
End of 5/10 1:19AM
Continue 
https://www.w3schools.com/python/python_numbers.asp
Tomorrow
 
"""