# Methods
# Methods are functions that belong to an object
# Methods are specific to the data type for a particular variable
sample_string = "I Love Programming"
sample_string.islower()
temp = sample_string.lower()
temp.islower()
sample_string.count('m') # count how many occurences of the letter 'm' in the string.
print(sample_string)
print(sample_string[3])
sample_string.find('o') # find the index of the first occurence of 'o' in the string
I Love Programming
o
# The format method for strings
number_of_laptops = 27
print("Antonio has {} laptops.".format(number_of_laptops))
animal = "dragon"
action = "fly"
print("Does your {} {}?".format(animal, action))
Antonio has 27 laptops.
Does your dragon fly?
# Exercise: fix a string
some_quote = 'You\'ll do what you can do--and won\'t do what you can\'t do.'
print(some_quote)
You'll do what you can do--and won't do what you can't do.
# Joey, Leslie, and Antonio have worked hard and generated some sales revenue for their company.
# Calculate and print the total sales from the data provided.
# Print out a string of the form "Total sales: xxx", where xxx will be the actual total
# You’ll need to change the type of the input data in order to calculate that total.
joey_sales = "121"
leslie_sales = "105"
antonio_sales = "110"
# TODO: Print a string with this format: Total sales: xxx
total_sales = int(joey_sales) + int(leslie_sales) + int(antonio_sales)
print("Total Sales: " + str(total_sales))
Total Sales: 336
# .title method
"Juan leal antonio ruiz".title()
# .split method
# Pangram contains all letters of the english alphabet a-z.
sample_str = "The quick brown fox jumps over the lazy dog." # pangram
sample_str.split()
another_str = "apple,banana,coconut,durian"
another_str.split(sep=",")
# Write a log message for a server
# using the data provided
username = "Joey"
timestamp = "16:50"
url = "http://evergreeninstitute.com/staff/courses/english"
# TODO: print a log message using the variables above.
# The message should have the same format as this one:
# "Leslie accessed the site http://evergreeninstitute.com/staff/course/python at 15:00."
message = "{} accessed the site {} at {}".format(username,url,timestamp)
print(message)
Joey accessed the site http://evergreeninstitute.com/staff/courses/english at 16:50
given_name = "Antonio"
middle_names = "Juan Leal"
family_name = "Ruiz"
#TODO: find the length of Antonoio's name, also make sure to count spaces
#name_length = len(given_name)+len(middle_names)+len(family_name)+2
name_length = len(given_name + middle_names + family_name ) + 2
print(name_length)
22
1/0
ZeroDivisionError: division by zero
len("abc"
SyntaxError: unexpected EOF while parsing (<ipython-input-47-f4696c987a1f>, line 1)
len(1)
TypeError: object of type 'int' has no len()