# Chapter2.py # Line Comment ''' Block Comment Multi Line Comment 3 single quotes ''' # Pythonic "Best Community Practices" ## readability, framework, resource allocation ### Framework Object Orientated Programming ''' Application/Program/Module -> TitleCase ShoppingCart.py Factory -> TitleCase PROVIDERS -> UPPERCASE -> api, inputs, outputs, file I/O Services -> web services, micro services, dependencies -> TitleCase Class -> Isolate Reusable Blocks of Code -> TitleCase Level 2 # Class Contacts Level 1 -> Object # Object Contact -> camelCase, underscore_case objContact property of an object -> 1. variable name 2. type firstname -> Contacts.Contact.firstname -> lowercase value -> assigned 'Bob' return value -> terminal, file, web, app, obj ''' # Python Core functions -> accessable by the installation of python # Python Standard functions -> accessable with the import keyword but installed with python ## import csv L1 # Custom/pip installed functions -> your functions L1, pip install L2/L3 # page 33 / 35 print,int,str,float -> Core print() # this will print an empty line "empty function" print('Hello, my name is Philip') # return string value # variables ## Law of Demeter Principle of Least Knowledge ## declare variables that we plan to call in scope firstname = 'Bob' # varname firstname type 'string' assigned value Bob print(firstname) age = 21 # int price = 52.42 # float orderStatus = True # bool True or False shipStatus = 'True' # string cost = "41.25" # string all inputs by default are string f_cost = float(cost) # page 39 arithmetic operators a = 7 b = 3 c = 4 r1 = a + b * c # 19 print(r1) r2 = (a + b) * c # 40 (10)*4 print(r2) # differences when using the SAME symbol ## + addition operator number format (int,float,double,complex) ## + join operator (string) s1 = "7" s2 = "3" r3 = s1 + s2 print(r3) # compound operators page 41 ## addition and subtraction VS compound ## how to use the equal symbol = ## Equals Symbol ''' = assignment operator ASSIGNING VALUE == in equality to operator TESTS VALUE is x == 5 === strictly in equality to operator TESTS VALUE AND TYPE ''' # addition x = 1 # 1 x = x + 1 # 2 # compound (increment / decrement) y = 1 # 1 y += 1 # 2 # page 45 joining strings ## 3 methods to join strings 2 page 45 other is in cpt 4 ## join, interpolation with f-type, parameterization fname = "Jane" lname = "Doe" # Jane Doe # page 45 join using the + join_fullname = fname + " " + lname # joins 2 objects type print(join_fullname) # page 45 f string interpolation with template variables f_fullname = f"{fname} {lname}" # outputs 2 values !type print(f_fullname) # chapter 4 parameterization param_fullname = fname,lname print(param_fullname) # page 47 escape chars # literal chars vs logical code string1 = "Type \"x\" to exit the application" print(string1) path1 = f"C:\foldername\filename.txt" # using a print() to add a blank line print("Welcome to my application") # natural line break print() print("stuff here") # using a \n to add a new line print("Welcome to my application\n") print("stuff here") # page 52 input() function ## ALL inputs by default are type -> string price1 = 50 # Ask the user to input the quantity needed, using the input() and casting the input as an integer. quantity = int( input("Enter quantity needed: ") ) # what am I going to use this variable the MOST as # calculate the line total linetotal = price1 * quantity print(linetotal) # EOF Chapter2.py