Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # All the Ways to Print 2021/09/04
- # the print() function and basic string object manipulation
- # print() with no arguments
- print()
- # print() with one argument
- print("Simple, one argument print call.")
- # print() with multiple arguments
- print("Hello", "I'm", "Johnny", "Cash")
- print("Hello", "I'm", "Johnny", "Cash", sep="--")
- # hidden keyword arguments: end and sep
- # default end="\n" for a new line return
- # default sep=" "
- # Beyond print()
- # Ways we build up larger strings
- x = "Sue"
- # CONCATENATION with +
- myString = "My name is " + str(x) + ". How do you do?" # easy, but also easy to mess up
- # DATA CONVERSION SPECIFIERS or "STRING MODULO" %s %f %d %i
- myString = "My name is %s. How do you do?" % (x)
- # THE BEST WAY: string class .format() method
- myString = "My name is {}. How do you do?".format(x)
- print(myString)
- # Use the given username and phone to create a message that lets the user know that
- # you will be calling at a specified number for your appointment. Use the
- # format method to insert data into the printed message.
- # expected outcome:
- # Hi, Allen. I will call you at 888-555-0011 for our appointment.
- username = 'Allen'
- phone = 8885550011
- phone = str(phone)
- msg = "Hi, {}. I will call you at {}-{}-{} for our appointment.".format(username, phone[0:3], phone[3:6], phone[6:])
- print(msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement