Python
1: Print Function
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
18: Center method
19: If Statement
20: If else statement
21: Nested if-else Statement
22: if-elif-else statement
23: while loop
23.1: Example 1 while loop
23.2: Example 2 while loop
23.3: Example 3 while loop
24: Infinite loop
25: for loop
25.1: Example 1 for loop
26: break and continue statement
27: for loop with string
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
18: Center method
19: If Statement
20: If else statement
21: Nested if-else Statement
22: if-elif-else statement
23: while loop
23.1: Example 1 while loop
23.2: Example 2 while loop
23.3: Example 3 while loop
24: Infinite loop
25: for loop
25.1: Example 1 for loop
26: break and continue statement
27: for loop with string
Chapter 15: Some useful function and methods
In this chapter, we will explore some commonly used functions and methods in Python for string manipulation.
len() Function: Returns the length of a string, including spaces.
name = "Free Learning"
length = len(name) # Total Length
print(length)
Ouptut: 13lower() Method: Converts all characters in a string to lowercase.
name = "FreE Learning"namelower = name.lower() # Lower Caseprint(namelower)Ouput: free learningupper() Method: Converts all characters in a string to uppercase.
name = "Free Learning"nameupper = name.upper() # Upper Caseprint(nameupper)Ouput: FREE LEARNINGtitle() Method: Capitalizes the first letter of each word in a string.
name = "FreE Learning"nametitle = name.title() # Sentence Caseprint(nametitle)Output: Free Learning
count() Method: Counts the occurrences of a specified character in a string.
name = "FreE Learning"count_e = name.count('e') # case-sensitiveprint(count_e)Ouput: 2Note: Methods like lower(), upper(), title(), and count() are used with the dot operator (.).