-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring2.py
More file actions
40 lines (33 loc) · 912 Bytes
/
Copy pathstring2.py
File metadata and controls
40 lines (33 loc) · 912 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
36
37
38
39
40
#string concatenation
first_name="deekshitha"
last_name="darshan"
full_name=first_name + " " + last_name #for space
print(full_name)
#repetition
message="warning "
print(message*5)
#string method
message="good morning! "
print(message.upper())#prints in capital letters
print(message.lower())#prints in small letters
print(message.strip()*3)#prints the output without space
print(message.replace("morning","night"))#replces a particualar string
name='''darshan said me "hi"
i said "hello"
'''
print(name)
message="hello hi"
print(len(message))#to count the number of characters including space
#accessing string
name="python"
print(name[1])
#string slicing
print(name[1:6])
print(name[:6])
print(name[-2]) #from reverse order
print(name[::2]) #[start:stop:step]
#escape sequence
name="darshan is \na good boy" #for next line
print(name)
name="darshan is \ta good boy" #for tab space
print(name)