fruits = ['apple', 'banana', 'orange']
# Get the elements of fruits using a for loop, and print 'I like ___s'
for fruit in fruits:
print ('I like '+ fruit+'s')
Reference:
Charles Severance's Python for Informatics
IN and NOT IN
if "H" in "Hello":
print("Yes")
"Z" not in "HEllo"
Identify the working directory
import os
os.getcwd()
Change the working directory (On my computer, I need double \ ).
os.chdir('c:\\temp')
Read a file and print a line that includes a search word (p. 129 of Python for Informatics)
import os
import re
os.chdir('C:\\temp')
hand=open('macro1.txt')
for line in hand:
line=line.rstrip()
if re.search('Madison',line):
print (line)