-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstring_methods.py
More file actions
38 lines (20 loc) · 1.34 KB
/
Copy pathstring_methods.py
File metadata and controls
38 lines (20 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
example_sentence_1 = " Python is easy to learn. "
example_sentence_2 = "python is easy to learn"
print (example_sentence_2.capitalize()) # turns the first letter of first word into upper case
print ("PYTHON IS EASY TO LEARN".casefold()) # Returns the sentence in small letters
print (example_sentence_1.center(29)) # Add given number of spaces before the center of the string
print (example_sentence_1.count("i")) # Returns the count of a char in a string
print (example_sentence_1.find("t")) # Returns the index of a char in the string
print (example_sentence_1.index("t")) # Returns the index of a char in the string
print (example_sentence_1.strip()) # Removes white space at begining or ending of a string
print (" ".join(example_sentence_2)) # joins every character with the given character (space in this example)
print (example_sentence_1.replace("easy","super easy")) # replace a word with the given word
print ("{name} is {level} to learn".format(name="Python",level="easy"))
print ("Hello {first_name} {last_name}! How are you ? ".format(first_name="John",last_name="K"))
first_name = "Name"
last_name = "Last Name"
print (f"Hello {first_name}, {last_name}! How are you ?")
print ("Hello %s %s How are you"%(first_name,last_name))
# %d - integers
# %f - floats
# %s - strings