-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.String.py
More file actions
33 lines (15 loc) · 792 Bytes
/
15.String.py
File metadata and controls
33 lines (15 loc) · 792 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
# Strings are immutable i.e. can't be changed - i.e. can't replace a with b
name = "Divit"
nameshort = name[0:3] # Starts from 0 then goes to 2 i.e. 0,1,2 and 3 will be excluded, it's like telling it that don't count anything starting from 3rd Index
print(nameshort)
char1 = name[4]
print(char1)
# negative slicing
print(name[0:3])
print(name[-4:-1]) # arr i.e. in -ve value goes like -4, -3, -2, -1, 0
print(name[1:4]) # arr cause yk why
print(name[1:]) # ivit cause starts from 1 index and goes till the last
print(name[:4]) # Divi cause takes 0 to 3 and yk from 4 it excludes everything
# Skip slicing
number = "0123456789"
print(number[1:8:2]) #starts from index value 1, exclude value of index 8, and add 2 to 1 and gives output - 1357