How to strip whitespace in Python? #shorts

preview_player
Показать описание
Whitespace is simply spacing between characters, or before the letters in a string... You get it, it's only the empty space. Now, Python is paying attention to that. Let me explain:

a = " Hi"
b = "Hi"

Variables a and b, in Python, if you check for equality you will see 2 different things, because of the whitespace. But, you can deal with whitespace really easily.

.lstrip() - used to strip left whitespace
.rstrip() - used to strip right whitespace
.strip()- used to strip left and right whitespace

NOTE: the whitespace is only temporarily (for 1 print statement) removed, to remove it permanently you have to assign the variable to another variable with the stripping method that you want.

Example:

Hi
Instead of:
Hi

--------------------------Subscribe-----------------------------
• If you like to see a variety of fun and interactive projects written in Python
• If you love ☕ and 🐶 WAIT! - Yeah! Definitely, coffee and dogs!
-----------------------------------------------------------------------

--------------------------Socials-----------------------------
------------------------------------------------------------------

--------------------------Support-----------------------------
--------------------------------------------------------------------

#indentation #python
How to strip whitespace in Python? #shorts
Рекомендации по теме
join shbcf.ru