-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_7String_Master.py
More file actions
82 lines (44 loc) · 1.09 KB
/
Python_7String_Master.py
File metadata and controls
82 lines (44 loc) · 1.09 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
String : Simply text in python
"word" more preferred ["" double quotation]
'word'
"""
#create a string
name = "OM"
#print(name)⭐
#How to concatinate +
surname = "BACCHUWAR"
print(name + surname)#❌
print(name,""+surname)#✅
print(name,surname)#✅
#How to access the word from the string
#Indexing is used to access the particular word from the str
#name = "OM"
# O = 0 and M = 1 are the indexing for the word OM
print(name[0],""+name[1])
language = "Python"
first_char = language[0]
third_char = language[2]
print(first_char,third_char)
#How to replace a string
sentence = "I love you JAVA" #lwda mera
new_sentence = sentence.replace("JAVA","PYTHON")
print(sentence)
print(new_sentence)
#How to find length of a string
coding = "Pyhton"
print(len(coding))
print(len(new_sentence))
#How to convert int into str
_name = "OM"
_age = 21
#print(_name+_age) Obviously this will give us error. Because the datatype which we are adding are of different types.
print(_name + str(_age))
#REPLACE METHOD
"""
Syntax
string.replace("old","new")
1- Search
2- Replacing
3- Result
"""