Wednesday, June 22, 2022

Python - Start here

# This is a comment
x = 5  # This is another comment
y = 2
"""
This is an interesting way to make
a multi-line comment.
But it is probably convenient to comment out a bunch of code this way.
"""

z = "Hello world"

if x > y:
    print("Five is greater than 2")
print("Out of the if branch")

# Here we see the variables were set above
print("x:")
print(x)
print("y:")
print(y)
print("z:")
print(z)

# Now we redefine the variables to different types on the fly
x = "apple"
y = "banana"
z = 400

# Here we see the redefined variables worked
print("x:")
print(x)
print("y:")
print(y)
print("z:")
print(z)

# This tells us the data type
print("z is a")
print(type(z))

# This lets us recast a variables type as a different type
z = str(z)

print("z:")
print(z)
print("z is a")
print(type(z))

# Both single and double quotes work
firstName = "John"
lastName = 'Doe'

myVar = "John"
myVAR = "Doe"

# Case sensitive variable names
print("myVar:")
print(myVar)

print("myVAR:")
print(myVAR)

# Assign 3 variables three different values
x, y, z = "John", "Doe", "Smith"
print(x)
print(y)
print(z)

# Assign 3 variables the same value is evil!
multi = variable = declaration = "evil"
print(multi)
print(variable)
print(declaration)

# Unpacking is cool: This snippet "unpacks" a list into three different variables
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)    # x will be set to apple
print(y)    # y will be set to banana
print(z)    # z will be set to cherry

# Here is a way of printing all three variables on the same line
print(x, y, z)  # Output: apple banana cherry

# Here is another way but no space in between each value
print(x + y + z)    # Output: applebananacherry

x = 10
y = 5
print(x + y)    # Output: 15

x = "John"
y = 5
z = "years old"

print(x, "is", y, z)    # Output: John is 5 years old

exit()