-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpycodes100_17_strings.py
More file actions
35 lines (32 loc) · 923 Bytes
/
pycodes100_17_strings.py
File metadata and controls
35 lines (32 loc) · 923 Bytes
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
#https://newdigitals.org/2024/02/24/100-basic-python-codes/#using-strings
#Working with strings: objects that contain sequences of character data.
name="john"+" "+"smith"
print(name.title())
print("Hello {},you are {} years old".format(name.title(),28))
print(f"Hello {name.title()}")
print("It is {},he is {} years old and his name is {}!".format(False,28,"John Smith".title()))
print(name.replace("john smith","Said ZITOUNI"))
Output:
John Smith
Hello John Smith,you are 28 years old
Hello John Smith
It is False,he is 28 years old and his name is John Smith!
Said ZITOUNI
name="john"+" "+"smith"
print(name.replace("john smith","Said ZITOUNI"))
print(name.upper())
print(name.find("ohn"))
print(name.strip())
list=name.split(" ")
print(list)
s="$$John"
print(s.lstrip('$'))
Output:
Said ZITOUNI
JOHN SMITH
1
john smith
['john', 'smith']
John
#Read more about strings here
#https://realpython.com/python-strings/