Python Basics

# -*- coding: utf-8 -*-
"""
Created on Mon Dec 30 12:56:16 2019

@author: Bruce1
"""

# =======================================================================
# Comments
# =======================================================================
# 1. Hash  ( CNTR-1 )
# 2. Multiline comments """

"""
line1
line2
line3
"""

# 3. Varible naming conventions

# =======================================================================
# Variables
# =======================================================================
stringVar = 'text string 0'
booleanVar = True # or False
integerVar = 0
floatVar = 100.123

listVar  = ['string1', 'string2', 'string3']
dictVar  = {'key1':'value1', 'key2':'value2'}
tupleVar = (stringVar, booleanVar, integerVar, floatVar)


# =======================================================================
# Decisions
# =======================================================================
condition = 1 > 3 # False

# Comparisons > >= == <= < !=

condition = 'string1' in listVar
condition = booleanVar

if condition == True :
    print ("Condition is True - Do something")
else:
    print ("Condition is False - Do something else")


# =======================================================================
# Loops
# =======================================================================
for i in range(10):
    print (i)
    
for item in listVar:
    print (item)
    
x = True
count = 0

while x == True:
    
    if count > 4:
        x = False
        
    #count = count + 1
    count += 1
    
    print ("Count = ",count , "x = ", x)
    print ("")
    
print ("Out of Loop")
    
    
# =======================================================================
# Functions
# =======================================================================
def functionXYZ (inputVar):
    
    if inputVar > 1:
        returnVar = inputVar *10.34
    else:
        returnVar = 0
        
    return returnVar

x = functionXYZ (floatVar)

print ("floatVar = ", floatVar)
print ("x        = ", x)

# =======================================================================
# Output
# =======================================================================
print ("")
print ("floatVar = {:.1f}".format(x))
print ("floatVar = {:.2f}".format(x))
print ("floatVar = ${:.2f}".format(x))
print ("floatVar = ${:,.2f}".format(x))
print ("floatVar = {:.1f} {:.1%}".format(x, x))