Advertisement
jspill

webinar-print-2021-04-03

Apr 3rd, 2021
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. # All the Ways to Print
  2. # print() and basic string object manipulation
  3.  
  4. # 1 argument
  5. print("Simple, one argument print call")
  6. x = "Sue"
  7. print(x)
  8.  
  9. # concatenating a larger string as an arg
  10. print("My name is " + str(x) + ", how do you do?")
  11.  
  12. # data conversion specifiers or "string modulo"
  13. print("I bet there's rich folks %s in a fancy %s" % ("eating", "dining car"))
  14.  
  15. # string class .format()
  16. print("They're probably drinking {} and smoking big {}!".format("coffee", "CIGARS"))
  17. # concatenation, string modulo, and string.format() call also be used to create new strings as well
  18. myString = "They're probably drinking {} and smoking big {}!".format("coffee", "CIGARS")
  19.  
  20. # print() can take multiple arguments
  21. # this can NOT create a new string object, it's only for print()
  22. c = "Cash"
  23. print("Hello. ", "I'm ", "Johnny ", c, ".", sep="", end=" ") # defaults: sep=" " and end="\n"
  24. print("Welcome to the show.")
  25.  
  26. # other methods you'll see later that also use keyword parameters with default values
  27. myList.sort(reverse=False) # usually this is what you want so you just leave out reverse parameter
  28. import datetime
  29. dt = datetime.timedelta(days=5) # default: weeks=0, days=0, hours=0... etc
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement