ALL 47 STRING METHODS IN PYTHON EXPLAINED

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ม.ค. 2025

ความคิดเห็น • 176

  • @jumper0122
    @jumper0122 2 ปีที่แล้ว +138

    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 10 หลายเดือนก่อน +1

      Lol, I never knew that! I always just use split() with join haha

    • @comandanteej
      @comandanteej 9 หลายเดือนก่อน +1

      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 9 หลายเดือนก่อน

      ​@@StampleD2147AI Using split() and join() is still useful when trying to remove multiple whitespaces between words.

    • @andrasbekes
      @andrasbekes 9 หลายเดือนก่อน +1

      And also removes new line character (
      ), thats handy when reading from a file.

  • @kiryonnakira7566
    @kiryonnakira7566 2 ปีที่แล้ว +31

    Honestly, the format method deserves a video on it's own.

    • @arnowinter462
      @arnowinter462 2 ปีที่แล้ว +8

      And f-string as well....

    • @proxima458273
      @proxima458273 11 หลายเดือนก่อน +6

      .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 ปีที่แล้ว +13

    One of the greatest videos about python strings I have watched on TH-cam. 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!

  • @midnightanna9925
    @midnightanna9925 ปีที่แล้ว +4

    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!"))

  • @IThinkItsMe
    @IThinkItsMe 8 วันที่ผ่านมา

    it took you 50 minutes. I spent 3 hours going through every excercise and trying them out in some code. Thanks for your efforts. Love from UK.

  • @HooverDamnn
    @HooverDamnn 3 หลายเดือนก่อน +1

    This really helped me get an understanding of writing code on the basic level and complete problem sets. Thank you brother👍

  • @dzendys_
    @dzendys_ 2 ปีที่แล้ว +19

    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

  • @grzegorzryznar5101
    @grzegorzryznar5101 2 ปีที่แล้ว +11

    Thanks for video!.
    1. For isalnum() also "_" is valid
    2. ascii is pronounced as "aski"

    • @MuslimMan377
      @MuslimMan377 11 หลายเดือนก่อน +1

      "_" isnt valid for isalnum() just checked 😊

    • @julians.2597
      @julians.2597 11 หลายเดือนก่อน +1

      @@MuslimMan377 and neither is "1_000"

  • @FoolBear404
    @FoolBear404 28 วันที่ผ่านมา

    finally a good course from a special italian dude ! grazie

  • @GeoMan1217
    @GeoMan1217 2 ปีที่แล้ว +5

    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  2 ปีที่แล้ว +1

      I’m the same, finding ideas like this to record is what I really enjoy doing, and even better if they help people :)

  • @rje4242
    @rje4242 ปีที่แล้ว +7

    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.

  • @sorin32
    @sorin32 2 ปีที่แล้ว +4

    Really nice video, thanks.
    on the endswith() you can also use another string not a single char, i.e. “apple”.endswith(“ple”)

    • @ProfRoxas
      @ProfRoxas 2 ปีที่แล้ว +1

      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

  • @KinkyJalepeno
    @KinkyJalepeno 6 หลายเดือนก่อน

    Love this video series - I'm documenting every single bit of them in my IDE as reference material

  • @cerealport2726
    @cerealport2726 2 ปีที่แล้ว +1

    As usual, I learned something new from this video! It's a really useful summary!

  • @OddiyBola-q6b
    @OddiyBola-q6b ปีที่แล้ว

    brother this is the best video when i seen, short but all methods understandable

  • @vasquezg86
    @vasquezg86 ปีที่แล้ว

    Great Vid! I'm learning Data Analytics rn using Python. Your content is helping me out. Thank you!

  • @Artistic_Indian_kid
    @Artistic_Indian_kid หลายเดือนก่อน

    Thanks for getting straight to the point with every form sir 🎉❤

  • @chairfacenope5836
    @chairfacenope5836 10 หลายเดือนก่อน

    This was very consice and easy to follow; thank you for the time stamps.

  • @311DaveR
    @311DaveR 9 หลายเดือนก่อน

    Love this, really nice refresher, and some that I was not aware of. Thank you.

  • @DaryaIbrahim
    @DaryaIbrahim 2 ปีที่แล้ว

    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!

  • @amarnathmishra8697
    @amarnathmishra8697 ปีที่แล้ว +1

    Bruv , Make a cheat sheet for all 47 methods . You have covered everything . We need to have a cheat-sheet with examples handy.

  • @mohamed-triki
    @mohamed-triki ปีที่แล้ว +3

    This video is literally GOLD !!!

  • @mohamad_subhi
    @mohamad_subhi 11 หลายเดือนก่อน

    i think this is the most useful video i've seen today thanks for your effort 😍

  • @khalilmahmoodiyan975
    @khalilmahmoodiyan975 3 หลายเดือนก่อน

    Thanks for the nice and helpful info.💚

  • @chestnutmongrel
    @chestnutmongrel 10 หลายเดือนก่อน +1

    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().

  • @facilvenir
    @facilvenir 8 หลายเดือนก่อน

    Great video. Mot likely I'll have to come back eventually hahaha I really like your channel.

  • @kevon217
    @kevon217 ปีที่แล้ว

    Love videos like this. Thanks for sharing!

  • @u424j24
    @u424j24 ปีที่แล้ว

    wow bro thanks greets from Uzbekistan🙌👍

  • @azizbekbarotboyev8015
    @azizbekbarotboyev8015 ปีที่แล้ว

    A must-have video for beginners. thanks

  • @ironmonkey1990
    @ironmonkey1990 4 หลายเดือนก่อน

    thank you for making this video!

  • @thinkinganame6173
    @thinkinganame6173 6 หลายเดือนก่อน

    Great explanation and very useful

  • @lte7151
    @lte7151 ปีที่แล้ว +5

    8:27 those numbers are Chinese

  • @perfect_man6263
    @perfect_man6263 11 หลายเดือนก่อน

    its been a year! and still a wonderful video :)

  • @frenamakenson9844
    @frenamakenson9844 ปีที่แล้ว

    thanks for sharing man, good explanation

  • @KriptoKenYT
    @KriptoKenYT ปีที่แล้ว

    Thank you bro, im making sure im all refreshed for my final tomorrow lol

  • @r.v.e3361
    @r.v.e3361 ปีที่แล้ว

    this is so good, Thx for that

  • @SannaJawara-m7l
    @SannaJawara-m7l ปีที่แล้ว

    You are superb ma bro ❤ i really understand your explanation

  • @irvinmuziwenkosi
    @irvinmuziwenkosi ปีที่แล้ว

    You are the best. Everything is well explained
    🤩

  • @ArmanAdabi
    @ArmanAdabi ปีที่แล้ว

    Thank you very much, your are a gift!!!

  • @ericmunschi4655
    @ericmunschi4655 2 ปีที่แล้ว

    Very interesting and usefull ! Thanks

  • @Lets_code_together_
    @Lets_code_together_ 10 หลายเดือนก่อน

    Thanks for the knowledge...................... it's just insane lecture

  • @muhammadaliqosimov7228
    @muhammadaliqosimov7228 6 หลายเดือนก่อน

    thank you for all explanations

  • @TomAndGingeCoLtd1996
    @TomAndGingeCoLtd1996 3 หลายเดือนก่อน

    5:15 in python 3.6 and later, often f-strings are cleaner than .format()

  • @uvanana.
    @uvanana. ปีที่แล้ว +1

    Thanks a lot :)

  • @theedspage
    @theedspage ปีที่แล้ว

    Thank you, this video is very informative.

  • @esergey12
    @esergey12 ปีที่แล้ว

    Very useful. Thanks 👍

  • @ceklahn
    @ceklahn 4 หลายเดือนก่อน

    print('Interesting and helpful!)

  • @mubaligh_e_azam_mission
    @mubaligh_e_azam_mission 10 หลายเดือนก่อน

    Very very good lecture

  • @zeicold
    @zeicold 9 หลายเดือนก่อน

    8:21 these are actually Chinese digis btw

  • @The-fishs-crypt
    @The-fishs-crypt 7 หลายเดือนก่อน

    my brother in Christ that’s mandarin. Great vid btw 9:17

  • @Anzeljaeg
    @Anzeljaeg 7 หลายเดือนก่อน

    Amazing content ty

  • @richardboreiko
    @richardboreiko 2 ปีที่แล้ว +1

    TH-cam says that two videos in the playlist are hidden - can you tell us what they are or unhide them?

  • @vishalprajapati1004
    @vishalprajapati1004 ปีที่แล้ว

    Very useful thank you sir❤

  • @callbettersaul
    @callbettersaul 2 ปีที่แล้ว +5

    What's the difference between casefold() and lower()?

    • @dzendys_
      @dzendys_ 2 ปีที่แล้ว +15

      casefold is more aggresive than lower -> example with german ß, casefold will make it ss but lower wont do anything

    • @callbettersaul
      @callbettersaul 2 ปีที่แล้ว

      @@dzendys_ Thank you for the quick response :).

  • @trevorli2697
    @trevorli2697 ปีที่แล้ว

    Thanks for sharing, Big help!
    BTW, 8:30 those are Chinese numbers! hahhah

  • @lorak95
    @lorak95 ปีที่แล้ว +1

    Would be cool to do the same with DICTs and LISTs. Many thanks!

    • @charlesotoghile6547
      @charlesotoghile6547 ปีที่แล้ว +1

      Creating a function to run desired string function against each item on the list should solve this

  • @KeithKazamaFlick
    @KeithKazamaFlick 11 หลายเดือนก่อน

    great video .
    do more method vidoes

  • @munivoltarc
    @munivoltarc 11 หลายเดือนก่อน

    Hi, could you make a video on functions of python from basic to advanced, and nested functions and class methods nested functions

  • @okporuanefeoghenevwegba5936
    @okporuanefeoghenevwegba5936 ปีที่แล้ว

    Thank you very much sir.

  • @jondo-vh8tx
    @jondo-vh8tx 5 หลายเดือนก่อน

    very nice video

  • @modeoinmoddle3995
    @modeoinmoddle3995 2 ปีที่แล้ว +5

    I didn't know there was an "isAshi()" method 🤣🤣🤣 (7:05)

    • @arnowinter462
      @arnowinter462 2 ปีที่แล้ว +1

      Me neither, I never heard "ASCII" pronounced that way... ;-)

  • @bogdanborta8861
    @bogdanborta8861 ปีที่แล้ว

    I ❤ your videos! Good job

  • @АлександрБеляков-й5м
    @АлександрБеляков-й5м 10 หลายเดือนก่อน

    Thank you!

  • @LidaTheBishop
    @LidaTheBishop 2 ปีที่แล้ว +1

    I LOVE YOU!☺

  • @MohammadAsgharShah
    @MohammadAsgharShah ปีที่แล้ว

    Looking for some DATABASE functions like CRUD!!!

  • @arunalakmal9031
    @arunalakmal9031 11 หลายเดือนก่อน

    Thanks dude

  • @vasunurukurthi5624
    @vasunurukurthi5624 ปีที่แล้ว

    rely very useful 😍😍

  • @misterkite7712
    @misterkite7712 2 ปีที่แล้ว

    Why do we need to use translate/maketrans? The replace method is really easier!

  • @treepiesinc1418
    @treepiesinc1418 2 หลายเดือนก่อน

    good one

  • @manzhizhang7194
    @manzhizhang7194 ปีที่แล้ว +1

    pretty useful videos, just in case, #17 are CHINESE NUMBERS!!

  • @OnlyXaM
    @OnlyXaM ปีที่แล้ว

    8:28 they are Chinese btw *

  • @wantstocomment7092
    @wantstocomment7092 ปีที่แล้ว

    I remembered to comment. Was that wazzzaaap speedy?

  • @whimsicalkins5585
    @whimsicalkins5585 ปีที่แล้ว

    Hellooo, 15:32 Guys. I loove this video

  • @Almulikie
    @Almulikie ปีที่แล้ว

    THANKS

    • @Indently
      @Indently  ปีที่แล้ว

      No problem

  • @ItsStaffDaddy
    @ItsStaffDaddy ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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 .... :

  • @rezahajivand7498
    @rezahajivand7498 ปีที่แล้ว

    Hello . Thanks

  • @Harveydent2001
    @Harveydent2001 9 หลายเดือนก่อน

    Gracias

  • @phantom008varun4
    @phantom008varun4 9 หลายเดือนก่อน

    Note guys these methods do not alter the actual data that variable is constant...

  • @largewallofbeans9812
    @largewallofbeans9812 11 หลายเดือนก่อน

    Why exactly does .format_map(dict) exist? Couldn't you just do .format(**dict)?

  • @mallninja9805
    @mallninja9805 10 หลายเดือนก่อน

    Is casefold different from lower in any way?

    • @Sophia_Travels
      @Sophia_Travels หลายเดือนก่อน

      Yes

    • @Sophia_Travels
      @Sophia_Travels หลายเดือนก่อน

      Lower only lowers english words

    • @Sophia_Travels
      @Sophia_Travels หลายเดือนก่อน

      Casefold takes every case and lowers it

    • @Sophia_Travels
      @Sophia_Travels หลายเดือนก่อน

      Like β is ss

    • @Sophia_Travels
      @Sophia_Travels หลายเดือนก่อน

      At least I think it's like that

  • @BeardBarians
    @BeardBarians 2 ปีที่แล้ว +1

    You could've used enumerate in the loop at the start!!

    • @Indently
      @Indently  2 ปีที่แล้ว +2

      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 2 ปีที่แล้ว +1

      @@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 2 ปีที่แล้ว +1

      @@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  2 ปีที่แล้ว +3

      Isn’t this just a chatgpt output?

    • @BeardBarians
      @BeardBarians 2 ปีที่แล้ว +1

      @@Indently Which one lmao

  • @philtoa334
    @philtoa334 ปีที่แล้ว

  • @Chuen666
    @Chuen666 ปีที่แล้ว

    I don't like to use "format()", just ues f-string, it's mort ez to understand and read

  • @kiryonnakira7566
    @kiryonnakira7566 2 ปีที่แล้ว +3

    0:52 xDD i saw that

  • @moonilyas
    @moonilyas ปีที่แล้ว

    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?

  • @sepehrhaghverdi8977
    @sepehrhaghverdi8977 7 หลายเดือนก่อน

    I learn something new

  • @hlubradio2318
    @hlubradio2318 9 หลายเดือนก่อน

    Hey is it just me or is VS Code faster in code suggestions eg AI

  • @asmitdutta
    @asmitdutta 2 ปีที่แล้ว

    can you make a finger counting app

  • @memo_force
    @memo_force ปีที่แล้ว

    What your IDE you use?

  • @thiyagua3188
    @thiyagua3188 10 หลายเดือนก่อน

    Nice

  • @3DartEnthusiast1157
    @3DartEnthusiast1157 2 ปีที่แล้ว

    which compiler u using?

  • @DerBarde2012
    @DerBarde2012 11 หลายเดือนก่อน

    .lower and .casefold look similar to me

  • @venzdrop
    @venzdrop 5 หลายเดือนก่อน

    startswith()

  • @kvelez
    @kvelez ปีที่แล้ว

    Cool

  • @rondamon4408
    @rondamon4408 10 หลายเดือนก่อน

    Only 50 minutes to record?

  • @BenChangdar
    @BenChangdar 7 หลายเดือนก่อน

    cool

  •  2 ปีที่แล้ว

    How insert emoji into python code? :-)

    • @Indently
      @Indently  2 ปีที่แล้ว

      Can you be more specific? Because you can directly type -> 🔥 for example and it will be in your code.

    •  2 ปีที่แล้ว

      @@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  2 ปีที่แล้ว

      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.

    •  2 ปีที่แล้ว

      ​@@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.

  • @sophialarson3890
    @sophialarson3890 4 หลายเดือนก่อน

    That is Bacon Baby.

  • @joableandrosuarezcorrea1576
    @joableandrosuarezcorrea1576 ปีที่แล้ว

    what is the difference between replace() and maketrans()/ translate()

  • @richardboreiko
    @richardboreiko 2 ปีที่แล้ว

    The c in ascii should be pronounced like a k, not sh.