ALL 47 STRING METHODS IN PYTHON EXPLAINED

  Рет қаралды 116,069

Indently

Indently

Күн бұрын

Here are all 47 of the string methods that you will find in vanilla Python. How many of them do you know?
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels
00:00 Intro
00:36 capitalize()
00:56 casefold()
01:36 center()
02:02 count()
02:25 encode()
02:55 endswith()
03:34 expandtabs()
03:56 find()
04:45 format()
05:20 format_map()
05:26 index()
06:17 isalnum()
06:49 isalpha()
07:04 isascci()
07:24 isdecimal() / isdigit() / isnumeric()
09:35 isidentifier()
10:06 islower()
10:26 isprintable()
10:49 isspace()
11:05 istitle()
11:30 isupper()
11:52 join()
12:35 ljust()
12:58 lower()
13:16 lstrip.
13:42 maketrans() / translate()
14:57 partition()
15:27 removeprefix()
15:43 removesuffix()
15:59 replace()
16:47 rfind()
17:21 rindex()
17:44 rjust()
18:02 rpartition()
18:34 rsplit() / split()
19:59 rstrip()
20:17 splitlines()
20:56 startswith()
21:15 strip()
21:40 swapcase()
21:54 title()
22:16 upper()
22:17 zfill()
22:48 Wrapping it up

Пікірлер: 149
@jumper0122
@jumper0122 Жыл бұрын
I feel like the most useful case where you'd use strip() was left out of this video. When used with no parameters, it strips spaces from the beginning and the end of a string. It's used all the time as the first step in sanitizing data from user input. I loved this video regardless though! I did not know about some of these, namely the weird fill ones
@StampleD2147AI
@StampleD2147AI 2 ай бұрын
Lol, I never knew that! I always just use split() with join haha
@comandanteej
@comandanteej 2 ай бұрын
Also the difference between strip and removeprefix: the first one takes a list of characters that may be removed multiple times, while the second one just removes the parameter as a single string.
@Wave1dave
@Wave1dave Ай бұрын
​@@StampleD2147AI Using split() and join() is still useful when trying to remove multiple whitespaces between words.
@andrasbekes
@andrasbekes Ай бұрын
And also removes new line character ( ), thats handy when reading from a file.
@kiryonnakira7566
@kiryonnakira7566 Жыл бұрын
Honestly, the format method deserves a video on it's own.
@arnowinter462
@arnowinter462 Жыл бұрын
And f-string as well....
@proxima458273
@proxima458273 3 ай бұрын
.format() should only be considered for legacy code. F-strings are far superior and should be chosen in every case they can be used… much like List Comprehensions should be chosen wherever possible.
@aalnajim
@aalnajim 11 ай бұрын
One of the greatest videos about python strings I have watched on KZbin. It is comprehensive! One thing I want to add is the difference between lstrip and removeprefix. The first one removes all the characters specified in its arguments starting from the left of the string until it faces a character that is not in the list of characters specified in its argument. So, print(‘Luigi gui guard’.lstrip(‘Luig ‘)) will print “ard” The second one removes the substring passed to it. So, print(‘Luigi gui guard’.removeprefix(‘Luigi ‘)) will print “gui guard” The same thing apply for rstrip and removesuffix I enjoy watching your videos. Keep the great work!
@cerealport2726
@cerealport2726 Жыл бұрын
As usual, I learned something new from this video! It's a really useful summary!
@vasquezg86
@vasquezg86 8 ай бұрын
Great Vid! I'm learning Data Analytics rn using Python. Your content is helping me out. Thank you!
@311DaveR
@311DaveR 2 ай бұрын
Love this, really nice refresher, and some that I was not aware of. Thank you.
@dzendys_
@dzendys_ Жыл бұрын
The lstrip() was presented here very shortly and used only in one scenario. It is important to add that if the text was "someemos text", it would return " text". If you want to remove only the "some" from "someemos text", you can use removeprefix(). Be careful with this. Last thing someone mentioned it in comments was: "What if you didn't give it any parameters?" -> It would delete spaces only on the left side, if there had been some spaces ofc
@kevon217
@kevon217 Жыл бұрын
Love videos like this. Thanks for sharing!
@chairfacenope5836
@chairfacenope5836 2 ай бұрын
This was very consice and easy to follow; thank you for the time stamps.
@midnightanna9925
@midnightanna9925 5 ай бұрын
I typed out every string method as I followed this video! omg we did it! Thank you for such a valuable video!! viewer: str = "{subject} is: {action}." print(viewer.format(subject="Midnight Anna", action="subscribing!"))
@user-bp5pq7hi7q
@user-bp5pq7hi7q 5 ай бұрын
brother this is the best video when i seen, short but all methods understandable
@azizbekbarotboyev8015
@azizbekbarotboyev8015 8 ай бұрын
A must-have video for beginners. thanks
@mohamad_subhi
@mohamad_subhi 4 ай бұрын
i think this is the most useful video i've seen today thanks for your effort 😍
@DaryaIbrahim
@DaryaIbrahim Жыл бұрын
Wazzaaap, even though the index was my best one for some personal reasons , I found both center and expandtabs very useful in my current project, thanks to you as always, and happy new year!
@ericmunschi4655
@ericmunschi4655 Жыл бұрын
Very interesting and usefull ! Thanks
@frenamakenson9844
@frenamakenson9844 5 ай бұрын
thanks for sharing man, good explanation
@rje4242
@rje4242 Жыл бұрын
one thing that makes sense for learning is to logically group operations together, like print(text.center(20,'*')) print(text.ljust(20,'*')) print(text.rjust(20,'*')) 3 alignments that take the exact same parameters. also, isspace() counts ALL whitespace as spaces - so tabs and linefeeds count as well, more useful than testing only for the space character.
@facilvenir
@facilvenir 14 күн бұрын
Great video. Mot likely I'll have to come back eventually hahaha I really like your channel.
@theedspage
@theedspage 10 ай бұрын
Thank you, this video is very informative.
@okwudili6512
@okwudili6512 8 ай бұрын
Very useful video. Thanks a lot
@esergey12
@esergey12 Жыл бұрын
Very useful. Thanks 👍
@r.v.e3361
@r.v.e3361 7 ай бұрын
this is so good, Thx for that
@irvinmuziwenkosi
@irvinmuziwenkosi Жыл бұрын
You are the best. Everything is well explained 🤩
@KriptoKenYT
@KriptoKenYT Жыл бұрын
Thank you bro, im making sure im all refreshed for my final tomorrow lol
@user-cp7jz2oh1m
@user-cp7jz2oh1m 7 ай бұрын
Thank you very much, your are a gift!!!
@Anzeljaeg
@Anzeljaeg 9 күн бұрын
Amazing content ty
@perfect_man6263
@perfect_man6263 3 ай бұрын
its been a year! and still a wonderful video :)
@GeoMan1217
@GeoMan1217 Жыл бұрын
I enjoy these types of videos. I've used Python for years now but find myself using methods I'm more familiar with, and making them work instead of using the correct method and saving time. Keep up the great work!
@Indently
@Indently Жыл бұрын
I’m the same, finding ideas like this to record is what I really enjoy doing, and even better if they help people :)
@grzegorzryznar5101
@grzegorzryznar5101 Жыл бұрын
Thanks for video!. 1. For isalnum() also "_" is valid 2. ascii is pronounced as "aski"
@MuslimMan377
@MuslimMan377 4 ай бұрын
"_" isnt valid for isalnum() just checked 😊
@julians.2597
@julians.2597 3 ай бұрын
@@MuslimMan377 and neither is "1_000"
@Lets_code_together_
@Lets_code_together_ 2 ай бұрын
Thanks for the knowledge...................... it's just insane lecture
@Ibrohimtoshpolatov-gq6io
@Ibrohimtoshpolatov-gq6io 6 ай бұрын
wow bro thanks greets from Uzbekistan🙌👍
@sorin32
@sorin32 Жыл бұрын
Really nice video, thanks. on the endswith() you can also use another string not a single char, i.e. “apple”.endswith(“ple”)
@ProfRoxas
@ProfRoxas Жыл бұрын
yea, it's a bit misleading, since afaik python doesn't specifically have single characters and all these functions work with strings .replace() .startswith .endswith() etc
@user-te1jv3ub5l
@user-te1jv3ub5l 8 ай бұрын
You are superb ma bro ❤ i really understand your explanation
@vishalprajapati1004
@vishalprajapati1004 10 ай бұрын
Very useful thank you sir❤
@mubaligh_e_azam_mission
@mubaligh_e_azam_mission 2 ай бұрын
Very very good lecture
@user-fe9em2sg8l
@user-fe9em2sg8l 3 ай бұрын
Thank you!
@amarnathmishra8697
@amarnathmishra8697 Жыл бұрын
Bruv , Make a cheat sheet for all 47 methods . You have covered everything . We need to have a cheat-sheet with examples handy.
@okporuanefeoghenevwegba5936
@okporuanefeoghenevwegba5936 9 ай бұрын
Thank you very much sir.
@KeithKazamaFlick
@KeithKazamaFlick 3 ай бұрын
great video . do more method vidoes
@uvanana.
@uvanana. 5 ай бұрын
Thanks a lot :)
@arunalakmal9031
@arunalakmal9031 3 ай бұрын
Thanks dude
@silver-wp7ky
@silver-wp7ky 7 ай бұрын
thank you!
@mohamed-triki
@mohamed-triki 7 ай бұрын
This video is literally GOLD !!!
@bogdanborta8861
@bogdanborta8861 Жыл бұрын
I ❤ your videos! Good job
@vasunurukurthi5624
@vasunurukurthi5624 Жыл бұрын
rely very useful 😍😍
@LidaTheBishop
@LidaTheBishop Жыл бұрын
I LOVE YOU!☺
@richardboreiko
@richardboreiko Жыл бұрын
KZbin says that two videos in the playlist are hidden - can you tell us what they are or unhide them?
@munivoltarc
@munivoltarc 3 ай бұрын
Hi, could you make a video on functions of python from basic to advanced, and nested functions and class methods nested functions
@chestnutmongrel
@chestnutmongrel 3 ай бұрын
I think it's worth mentioning that neither isdecimal() nor isnumeric() nor isdigit() return True for a line '-1', regardles the line is perfectly fine for int().
@lorak95
@lorak95 Жыл бұрын
Would be cool to do the same with DICTs and LISTs. Many thanks!
@charlesotoghile6547
@charlesotoghile6547 5 ай бұрын
Creating a function to run desired string function against each item on the list should solve this
@bruhlickd
@bruhlickd Жыл бұрын
Make one with all methods of OS library!!!!
@Harveydent2001
@Harveydent2001 2 ай бұрын
Gracias
@memo_force
@memo_force Жыл бұрын
What your IDE you use?
@rezahajivand7498
@rezahajivand7498 10 ай бұрын
Hello . Thanks
@manzhizhang7194
@manzhizhang7194 8 ай бұрын
pretty useful videos, just in case, #17 are CHINESE NUMBERS!!
@asmitdutta
@asmitdutta Жыл бұрын
can you make a finger counting app
@Almulikie
@Almulikie 7 ай бұрын
THANKS
@Indently
@Indently 7 ай бұрын
No problem
@misterkite7712
@misterkite7712 Жыл бұрын
Why do we need to use translate/maketrans? The replace method is really easier!
@thiyagua3188
@thiyagua3188 2 ай бұрын
Nice
@MohammadAsgharShah
@MohammadAsgharShah 11 ай бұрын
Looking for some DATABASE functions like CRUD!!!
@kiryonnakira7566
@kiryonnakira7566 Жыл бұрын
0:52 xDD i saw that
@moonilyas
@moonilyas 8 ай бұрын
Hi there, Great topic for strings, but if I want run the code in start of video it is not working code is as follow: def get_string_methods(): i: int = 0 for method in dir(str): if not in method: i += 1 print(i) print(i ,method, sep=': ') Is there any thing missing in the code?
@trevorli2697
@trevorli2697 5 ай бұрын
Thanks for sharing, Big help! BTW, 8:30 those are Chinese numbers! hahhah
@mallninja9805
@mallninja9805 2 ай бұрын
Is casefold different from lower in any way?
@magicvibrations5180
@magicvibrations5180 Ай бұрын
What is the difference between casefold() and lower()?
@lte7151
@lte7151 Жыл бұрын
8:27 those numbers are Chinese
@callbettersaul
@callbettersaul Жыл бұрын
What's the difference between casefold() and lower()?
@dzendys_
@dzendys_ Жыл бұрын
casefold is more aggresive than lower -> example with german ß, casefold will make it ss but lower wont do anything
@callbettersaul
@callbettersaul Жыл бұрын
@@dzendys_ Thank you for the quick response :).
@zeicold
@zeicold Ай бұрын
8:21 these are actually Chinese digis btw
@modeoinmoddle3995
@modeoinmoddle3995 Жыл бұрын
I didn't know there was an "isAshi()" method 🤣🤣🤣 (7:05)
@arnowinter462
@arnowinter462 Жыл бұрын
Me neither, I never heard "ASCII" pronounced that way... ;-)
@shaheerhassan1157
@shaheerhassan1157 Жыл бұрын
which compiler u using?
@spaghettiking653
@spaghettiking653 Жыл бұрын
Probably CPython
@wantstocomment7092
@wantstocomment7092 6 ай бұрын
I remembered to comment. Was that wazzzaaap speedy?
@kvelez
@kvelez 7 ай бұрын
Cool
@whimsicalkins5585
@whimsicalkins5585 8 ай бұрын
Hellooo, 15:32 Guys. I loove this video
@phantom008varun4
@phantom008varun4 Ай бұрын
Note guys these methods do not alter the actual data that variable is constant...
@hlubradio2318
@hlubradio2318 Ай бұрын
Hey is it just me or is VS Code faster in code suggestions eg AI
@ItsStaffDaddy
@ItsStaffDaddy Жыл бұрын
Can someone give a use case where .isprintable() would be important? I'm sure it is useful, but I can't think of anything.
@ItsStaffDaddy
@ItsStaffDaddy Жыл бұрын
Disregard, despite the internet not having anything, ChatGPT gave some good use cases for normalizing strings before tokenizing and feeding it into NLP models and such.
@jyvben1520
@jyvben1520 11 ай бұрын
detects \t \v \u \b ... in one function call, returns False if found any of them. can not test just on "\\" or chr(92) in text which could be normal. no need for if "\t" in text or " " in text or " " in text .... :
@philtoa334
@philtoa334 Жыл бұрын
@user-hd3pz2ow1b
@user-hd3pz2ow1b 2 ай бұрын
cool
@Chuen666
@Chuen666 5 ай бұрын
I don't like to use "format()", just ues f-string, it's mort ez to understand and read
@OnlyXaM
@OnlyXaM 5 ай бұрын
8:28 they are Chinese btw *
@DerBarde2012
@DerBarde2012 3 ай бұрын
.lower and .casefold look similar to me
@BeardBarians
@BeardBarians Жыл бұрын
You could've used enumerate in the loop at the start!!
@Indently
@Indently Жыл бұрын
The count would not display properly with the code above because of the if check. But you're welcome to share some code and show me otherwise :)
@BeardBarians
@BeardBarians Жыл бұрын
@@Indently Ahh I didn't see the count before. After watching the video though, I thought would it be better to do if not method.startswith("__") instead of if not "__" in method as it would allow functions to have a __ inside of them, as well as not checking the whole string for the characters
@gardnmi
@gardnmi Жыл бұрын
@@Indently Here ya go. Thanks for the video. def print_methods(obj): methods = [m for m in dir(obj) if '_' not in m] for i, method in enumerate(methods): print(i + 1, method, sep=": ")
@Indently
@Indently Жыл бұрын
Isn’t this just a chatgpt output?
@BeardBarians
@BeardBarians Жыл бұрын
@@Indently Which one lmao
@joableandrosuarezcorrea1576
@joableandrosuarezcorrea1576 10 ай бұрын
what is the difference between replace() and maketrans()/ translate()
@largewallofbeans9812
@largewallofbeans9812 3 ай бұрын
Why exactly does .format_map(dict) exist? Couldn't you just do .format(**dict)?
@getstart98
@getstart98 5 ай бұрын
👍🙏
@esphilee
@esphilee 3 ай бұрын
I fell asleep after the 5th.. ya.. somewhere around there..
Жыл бұрын
How insert emoji into python code? :-)
@Indently
@Indently Жыл бұрын
Can you be more specific? Because you can directly type -> 🔥 for example and it will be in your code.
Жыл бұрын
@@Indently Specific? So, I dont know how to do it. You use at 13:49 some emoji as some character of string. But how I can type it? Its need for that some addon with browsing allowed emoji or what? You write "you can directly type" but how to directly type emoji of fire on keyboard?
@Indently
@Indently Жыл бұрын
Now I understand what you mean. On Mac I can do it by using a shortcut which gives me a small emoji table. You would have to search on Google whether there's an option for quick emoji insertion for your OS.
Жыл бұрын
​@@Indently So simply copy from somewhere and paste into code ? Ok, its seem easy. Btw thx for this video and video called "6 CLEAN Tips To IMPROVE Your Python Functions" , I learned a lot today. I subscribe you today.
@richardboreiko
@richardboreiko Жыл бұрын
The c in ascii should be pronounced like a k, not sh.
@arham2549
@arham2549 10 ай бұрын
i commeted
@grease253
@grease253 Жыл бұрын
Python gold
@rondamon4408
@rondamon4408 3 ай бұрын
Only 50 minutes to record?
@hanying_0705
@hanying_0705 7 ай бұрын
This video is good, but In # 17, those are not Japanese numbers, they are Chinese numbers!
@teabest2056
@teabest2056 7 күн бұрын
一二三四 is not a Japanese number, but a Chinese number
@niteshbabu5731
@niteshbabu5731 2 ай бұрын
3-4 of them were repeated 😂
@panxel8615
@panxel8615 7 күн бұрын
bruh.. casefold is just lower
@Indently
@Indently 7 күн бұрын
If you're feeling really confident, post that on Stack Overflow.
@panxel8615
@panxel8615 7 күн бұрын
@@Indently stack overflow is the reddit for programmers no ty LMAO
@Indently
@Indently 7 күн бұрын
Otherwise you'll find other people who think casefold and lower are the same on TikTok.
@panxel8615
@panxel8615 7 күн бұрын
@@Indently its a stronger lower method. yippe. im pretty good at python and have no idea how to improve from now
@jaredbrooks2226
@jaredbrooks2226 Жыл бұрын
Jesus loves you. Why don't you get to know him soon?
@Indently
@Indently Жыл бұрын
Is that a threat
@jaredbrooks2226
@jaredbrooks2226 Жыл бұрын
@@Indently *An invitation to look into something rather interesting but too often gets brushed aside.
@Indently
@Indently Жыл бұрын
From where I come from in Italy, getting to know Jesus is a completely different thing 😂
@jaredbrooks2226
@jaredbrooks2226 Жыл бұрын
@@Indently I didn't know of that. I only want you to get to know the Loving Maker of All Existence through accepting him as God and Savior.
@roseleyzhang4777
@roseleyzhang4777 7 ай бұрын
The content was pretty good but there was an error, at the video's 9:13, you said that the numbers were Japanese, but in reality that isn't true, it is Chinese, and that is really offensive!!! You just lost a subscriber, due to your lack of basic knowledge. Just some basic history, China has a longer history than Japan and came up with writing before Japan! It was created around 479 to 221 BC, and Japan adopted a lot of Chinese characters but that doesn't mean that they are Japanese!
@Indently
@Indently 7 ай бұрын
Thanks 🙏
@Naumkovich
@Naumkovich Жыл бұрын
hello, tell me how, when entering text, the print was spelled out, as if a person were typing?
@Indently
@Indently Жыл бұрын
I don’t understand, could you try rephrasing that?
@Naumkovich
@Naumkovich Жыл бұрын
@@Indently kek sorry) when outputting "PRINT", the text appeared letter by letter, not all at once
@Indently
@Indently Жыл бұрын
@@Naumkovich Where in the video did that happen?
@liverandlearn448
@liverandlearn448 Жыл бұрын
'.rstrip' still gives me the output: 'His name is Mario Mario.' ChatGPT says that 'The rstrip method in Python only removes trailing characters from the right side of the string, not characters within the string. To remove the second instance of "Mario" in the string, you can use string slicing or the replace method.' And then suggest 'text.replace('Mario', '', 1)' and when I prompt it to use '.rstrip' it tells me to use this: 'text[:text.rindex('Mario')] + text[text.rindex('Mario')+5:]'. What am I missing here?
@Indently
@Indently Жыл бұрын
A '.'
@liverandlearn448
@liverandlearn448 Жыл бұрын
@@Indently lol, how dumb of me. Thanks!
@arnowinter462
@arnowinter462 Жыл бұрын
Anyway, "ChatGPT" should not be your first choice when searching information. Do you know where this strange algorithm get the "information" from?
@liverandlearn448
@liverandlearn448 Жыл бұрын
@@arnowinter462 Ive asked it before and it doesnt want to divulge any specifics about itself or its training data. But asking that on stackoverflow would get be crucified, the less of two evils in these cases imo.
@nnyms-ov3ff
@nnyms-ov3ff Жыл бұрын
*chinese numbers
The FULL Guide To Itertools For Python Developers
29:11
Indently
Рет қаралды 14 М.
Please be kind🙏
00:34
ISSEI / いっせい
Рет қаралды 55 МЛН
Whyyyy? 😭 #shorts by Leisi Crazy
00:16
Leisi Crazy
Рет қаралды 19 МЛН
TRY NOT TO LAUGH 😂
00:56
Feinxy
Рет қаралды 13 МЛН
Python string format 💬
12:47
Bro Code
Рет қаралды 29 М.
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 29 М.
How to Use Strings in Python - Python Tutorial for Beginners
16:46
Programming with Mosh
Рет қаралды 223 М.
Python List
24:36
Eric Aggrey
Рет қаралды 52
Python Classes Tutorial #5 | Advanced Concepts
10:08
Aikonic
Рет қаралды 6 М.
Abstraction Can Make Your Code Worse
5:13
CodeAesthetic
Рет қаралды 611 М.
How To Use Recursion In Python
8:50
Taylor's Software Solutions
Рет қаралды 3,6 М.
ALL 11 Dictionary Methods In Python EXPLAINED
9:26
Indently
Рет қаралды 50 М.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 52 М.
Splash Screen In Android Studio [Kotlin]
2:41
Ravecode Android
Рет қаралды 3,4 М.