Advertisement
jspill

webinar-print-2021-09-04

Sep 4th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. # All the Ways to Print 2021/09/04
  2. # the print() function and basic string object manipulation
  3.  
  4. # print() with no arguments
  5. print()
  6.  
  7. # print() with one argument
  8. print("Simple, one argument print call.")
  9.  
  10. # print() with multiple arguments
  11. print("Hello", "I'm", "Johnny", "Cash")
  12. print("Hello", "I'm", "Johnny", "Cash", sep="--")
  13.  
  14. # hidden keyword arguments: end and sep
  15. # default end="\n" for a new line return
  16. # default sep=" "
  17.  
  18.  
  19.  
  20. # Beyond print()
  21.  
  22. # Ways we build up larger strings
  23. x = "Sue"
  24.  
  25. # CONCATENATION with +
  26. myString = "My name is " + str(x) + ". How do you do?" # easy, but also easy to mess up
  27. # DATA CONVERSION SPECIFIERS or "STRING MODULO" %s %f %d %i
  28. myString = "My name is %s. How do you do?" % (x)
  29. # THE BEST WAY:  string class .format() method
  30. myString = "My name is {}. How do you do?".format(x)
  31. print(myString)
  32.  
  33. # Use the given username and phone to create a message that lets the user know that
  34. # you will be calling at a specified number for your appointment. Use the
  35. # format method to insert data into the printed message.
  36. # expected outcome:
  37. # Hi, Allen. I will call you at 888-555-0011 for our appointment.
  38. username = 'Allen'
  39. phone = 8885550011
  40. phone = str(phone)
  41.  
  42. msg = "Hi, {}. I will call you at {}-{}-{} for our appointment.".format(username, phone[0:3], phone[3:6], phone[6:])
  43. print(msg)
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement