forked from chavarera/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.BasicOfStrings.py
More file actions
50 lines (34 loc) · 1.44 KB
/
1.BasicOfStrings.py
File metadata and controls
50 lines (34 loc) · 1.44 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
#Strings
#String is collection of Alphabets numbers and special charcter
#following are the some defualt string function
stringname=("kjdsfndnfd")
#stringname[1] gives j string started counting first charter as 0 second as 1 third as 2 in this way
print(stringname[1])
#j
#stringname[-10] gives k that counts from last character and search like d at -1, f at -2,-3...
print(stringname[-10])
#k
#selecting sub sequences from string
#Syantax variablename[starting position:endingposition + 1]
# for example if you want to print sfn from above stringname then where s is at starting position is 3 and n endpostion is 5 add 1 in it then total is 6
print(stringname[3:6])
#sfn
#stringnam[10] gives error index out of range
#print(stringname[10])
#you can use : for multiple use like
# variablename[startingpostion:] in this example if we just add starting postion then then resultant substring contains output from statring postion to last charcter
print(stringname[6:])
#dnfd
#variablename[:ending postion ] this will give output in such manner from starting to that ending position
print(stringname[:4])
#kjds
#variablename[:] this will give who string as output
print(stringname[:])
#kjdsfndnfd
#IMP NOTE
#if you provide out of range ending index it doesent give error it will print full string
print(stringname[:50])
#kjdsfndnfd
#if you provide out of range starting index it doesent give error it will print full string
print(stringname[-100:])
#kjdsfndnfd