Advertisement
jspill

webinar-strings-print-2022-07-09

Jul 9th, 2022
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. # We once called it "All the Ways to Print"... but printing isn't all we do to strings.
  2. # So we changed it to "String Manipulation and Printing"
  3. # but now it's
  4. # "Your Strings Are Jack Tripper"
  5.  
  6. name = "Sue"
  7. # different way to build up a longer string
  8.  
  9. # + Concatenation... easy to understand but the best to say
  10. myString = "My name is " + str(name) + ", how do you?"
  11.  
  12. # string modulo or "data conversion specifiers"
  13. myString = "My name is %s, how do you do?" % (name) # %i %d %f
  14. # str method .format()
  15. myString = "My name is {}, how do you do?".format(name)
  16. # f strings
  17. myString = f"My name is {name}, how do you do?"
  18.  
  19. print(myString)
  20.  
  21. import math
  22. print(math.pi)
  23. print("Pi to 3 decimal places is {:.3f}".format(math.pi))
  24. print(f"Pi to 3 decimal places is {math.pi:.3f}")
  25.  
  26.  
  27.  
  28.  
  29.  
  30. # Watch your string input and output
  31. # # 1
  32. # myVar = input().strip() # myVar = input().rstrip()
  33. # # 2
  34. # print("some stuff", end=" ") # if you ever override end
  35. # print() # print(end="\n")
  36.  
  37. for n in range(0, 7):
  38.     print("{} -> ".format(n), end="")
  39. print(7)
  40. print("The next thing")
  41.  
  42. # Know your WHITESPACE
  43. # " " # a space, from hitting the spacebar
  44. # # There are also about 20-25 other simple spaces in Unicode
  45. # "\n" # new line return
  46. # "\t" # tab
  47. # "\r" # carriage return, back to beginning of the current line
  48. # "\b" # backspace
  49. # "\f" # form feed
  50.  
  51. # str isspace()
  52. myVar = "George"
  53. print(myVar[-1].isspace()) # False
  54. myVar = "George\t"
  55. print(myVar[-1].isspace()) # True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement