Posts Python string functions
Post
Cancel

Python string functions

Python String Funtions

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
# string concatenation

string1 = 'tamil'
string2 = 'ctf'

string = string1 + string2
print(string)

# converting string to uppercase

string.upper()
print(string)

# converting string to lowercase

string.lower()
print(string)

# capitalise and title the string

string.capitalize()
print(string)
string.title()
print(string)

# Find the index of letter 'c' in 'tamilctf'

index = string.find('c')
print(index)

# Replace a part of string with new string

string.replace('ctf', 'CTF')
print(string)

# Traversing a string with loop

for i in string:
   print(i)

# converting string into a list

list_of_chars = list(string)

for char in list_of_chars:
    print(char)
    
# convert list into string

list_to_string = ''.join(list_of_chars)
print(list_to_string)

Hope you learnt about some functions

This post is licensed under CC BY 4.0 by the author.