#!/usr/bin/env python # coding: utf-8 # In[16]: # Section 2.2 and 2.3 print('Hello world!') # An example of a string is 'Hello world!' # A string is a list of characters inside of quotes # # This command makes an error: # print('Hello world!) # the error is that the string did not complete before the print command ended # # # Other ways to define a string: # most common: use double quotes: "a string is here" print("Hello world with double quotes!") # This one is bad because of syntax. There is not one string fed to the print command. #print('she's coming round the mountain') # print("she's coming round the mountain") print('she is coming round the "mountain" ') # # Can also do triples of the quote marks to define a string: '''string''' or """this is a string""" print("""she's coming round the "mountain" """) # # # # In[20]: # An "Argument" is what is plugged into a command # The command "print" is called a function # # Section 2.5 -- Variables # # age=25 # Format of variable assignments: # variable = expression/value/whatever # You cannot change the order and expect it to work properly: # 25=age #Compare print(age) print('age') # The following gives an error because Age is a different variable to python than age # print(Age) # In[37]: # Create two variables governor='Jim Justice' secofstate='Mac Warner' # Display my variables print('The governor is') print(governor) print('The secretary of state is') print(secofstate) # What can and cannot be the name of a variable? # 1. can't use a "key word" of python -- see Table 1-2 in Section 1.4 # 2. spaces cannot appear in a variable name # 3. first character has to be a letter a-z or A-Z or an underscore # 4. after the first character, can use a-z, A_Z, underscore, or numbers # 5. variable names are case sensitive # # # Advice: name variables after what they are used for!!! # For example: # pizzassold = 10 # is better than # p=10 # # # # How to put variables and strings in a print command: print('The governor is',governor,'.') print('The secretary of state is',secofstate,'.')