filmov
tv
Python String swapcase() Method : Python Tutorial for Beginners #yasirbhutta #pythonshorts

Показать описание
This Python code demonstrates the use of the swapcase() method to swap the case of characters in a given string.
# Example string
my_string = "Hello, World!"
# Using swapcase() method
# Print original and modified strings
print("Original String: ", my_string)
print("Modified String: ", new_string)
Here is a step-by-step explanation of the code:
The string "Hello, World!" is assigned to the variable my_string.
The swapcase() method is called on my_string, which creates a new string with the case of all alphabetic characters in the original string swapped (i.e., uppercase characters become lowercase and vice versa). This new string is assigned to the variable new_string.
The print() function is called twice to display the original string and the modified string on the console. The original string is displayed using the variable my_string, and the modified string is displayed using the variable new_string.
When you run this code, you will see the following output:
Original String: Hello, World!
Modified String: hELLO, wORLD!
As you can see, the swapcase() method has swapped the cases of all alphabetic characters in the original string.
If you enjoyed this video, please give it a thumbs up 👍and leave a comment 💬 below. Don't forget to subscribe 🔔to my channel for more Python tutorials like this one.
YouTube Playlists:
You can also follow me on:
Thanks for watching! 🙏**
#yasirbhutta #codingshorts #coding #pythonprogramming #pythonbasics #codingshortvideo #pythontutorial #codinglife #python #python
# Example string
my_string = "Hello, World!"
# Using swapcase() method
# Print original and modified strings
print("Original String: ", my_string)
print("Modified String: ", new_string)
Here is a step-by-step explanation of the code:
The string "Hello, World!" is assigned to the variable my_string.
The swapcase() method is called on my_string, which creates a new string with the case of all alphabetic characters in the original string swapped (i.e., uppercase characters become lowercase and vice versa). This new string is assigned to the variable new_string.
The print() function is called twice to display the original string and the modified string on the console. The original string is displayed using the variable my_string, and the modified string is displayed using the variable new_string.
When you run this code, you will see the following output:
Original String: Hello, World!
Modified String: hELLO, wORLD!
As you can see, the swapcase() method has swapped the cases of all alphabetic characters in the original string.
If you enjoyed this video, please give it a thumbs up 👍and leave a comment 💬 below. Don't forget to subscribe 🔔to my channel for more Python tutorials like this one.
YouTube Playlists:
You can also follow me on:
Thanks for watching! 🙏**
#yasirbhutta #codingshorts #coding #pythonprogramming #pythonbasics #codingshortvideo #pythontutorial #codinglife #python #python
Комментарии