-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringLtP3.py
More file actions
41 lines (34 loc) · 970 Bytes
/
StringLtP3.py
File metadata and controls
41 lines (34 loc) · 970 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
# To get the type of variable you can use type function
print(type(3))
print(type(3.14))
print(type("3"))
print(type('3'))
samp_string = "This is a very important string"
# You can get a specific character from string
print(samp_string[0])
print(samp_string[-1])
print(samp_string[3+5])
# You can get the length of the string
print("Length : ", len(samp_string))
# You can dissect the string to get just a part of it:
# from 8th index till end
print(samp_string[8:])
# from 0 to 4 index
print(samp_string[0:4])
# Concatenate strings
print("Green" + "Eggs")
# Multiply strings
print("Hello" * 5)
# Convert int into string
num_string = str(4)
# Cycle through each char in string
for char in samp_string:
print(char)
# Cycle through char in pairs
for i in range(0 , len(samp_string)-1, 2):
print(samp_string[i] + samp_string[i+1])
# Computers assign characters through UNICODE
# A - Z 65 - 90
# a - z 97 - 122
print("A = ", ord("A"))
print("97 = ", chr(97))