Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # We once called it "All the Ways to Print"... but printing isn't all we do to strings.
- # So we changed it to "String Manipulation and Printing"
- # but now it's
- # "Your Strings Are Jack Tripper"
- name = "Sue"
- # different way to build up a longer string
- # + Concatenation... easy to understand but the best to say
- myString = "My name is " + str(name) + ", how do you?"
- # string modulo or "data conversion specifiers"
- myString = "My name is %s, how do you do?" % (name) # %i %d %f
- # str method .format()
- myString = "My name is {}, how do you do?".format(name)
- # f strings
- myString = f"My name is {name}, how do you do?"
- print(myString)
- import math
- print(math.pi)
- print("Pi to 3 decimal places is {:.3f}".format(math.pi))
- print(f"Pi to 3 decimal places is {math.pi:.3f}")
- # Watch your string input and output
- # # 1
- # myVar = input().strip() # myVar = input().rstrip()
- # # 2
- # print("some stuff", end=" ") # if you ever override end
- # print() # print(end="\n")
- for n in range(0, 7):
- print("{} -> ".format(n), end="")
- print(7)
- print("The next thing")
- # Know your WHITESPACE
- # " " # a space, from hitting the spacebar
- # # There are also about 20-25 other simple spaces in Unicode
- # "\n" # new line return
- # "\t" # tab
- # "\r" # carriage return, back to beginning of the current line
- # "\b" # backspace
- # "\f" # form feed
- # str isspace()
- myVar = "George"
- print(myVar[-1].isspace()) # False
- myVar = "George\t"
- print(myVar[-1].isspace()) # True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement