Python string slicing ✂️

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ต.ค. 2024
  • Python string slice tutorial example explained
    #python #slice() #slicing
    slicing = create a substring by extracting elements from another string
    indexing[] or slice()
    [start:stop:step]
    name = "Bro Code"
    first_name = name[:3] # [0:3]
    last_name = name[4:] # [4:end]
    funky_name = name[::2] # [0:end:2]
    reversed_name = name[::-1] # [0:end:-1]
    print(reversed_name)
    website1 = "google.com"
    website2 = "wikipedia.com"
    slice = slice(7,-4)
    print(website1[slice])
    print(website2[slice])
    ------------------------------
    Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
    Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
    Free Download / Stream: bit.ly/2JnDfCE
    Music promoted by Audio Library • Up In My Jam (All Of A...
    ------------------------------

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

  • @BroCodez
    @BroCodez  3 ปีที่แล้ว +31

    # slicing = create a substring by extracting elements from another string
    # indexing[] or slice()
    # [start:stop:step]
    name = "Bro Code"
    first_name = name[:3] # [0:3]
    last_name = name[4:] # [4:end]
    funky_name = name[::2] # [0:end:2]
    reversed_name = name[::-1] # [0:end:-1]
    print(reversed_name)
    website1 = "google.com"
    website2 = "wikipedia.com"
    slice = slice(7,-4)
    print(website1[slice])
    print(website2[slice])

  • @paticruz3992
    @paticruz3992 ปีที่แล้ว +10

    Bro!!! You are the fourth video I watched on the slice operator, they all failed to answered the questions I had. You sir, have answered all my questions! Subscribed. :)

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

    Thanks for explaining indexing and the slice function. I’m taking an online course and they really didn’t explain. The negative numbers I liked, followed, and commented. Keep them coming.

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

    Your videos are tremendously helpful. I've been tearing my hair out learning from a course today but your videos makes so much more sense. Thank you!

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

      yeah I don't know the first thing about coding and all the videos I found assumed you knew the fundamentals. I even went so far as to start watching 'coding for kids' videos, but what this guy is doing is amazing! Breaking everything down from the very first steps, this dude is a legit bro.

  • @ChristopherRichardson-se1vb
    @ChristopherRichardson-se1vb 3 หลายเดือนก่อน

    Very concise. Python docs were confusing me on this and you really helped. Appreciate it.

  • @kawiurka
    @kawiurka 3 ปีที่แล้ว +6

    I start to understand everything, thank you so so much :) You are really good in teaching and its great video (all of them).

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

    Learned a lot. Thanks for the video.

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

    Thanks for walking us through this. I am just starting to learn how to code with Python and seeing you do this was really helpful. You have a new subscriber.

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

    Heavenly send. Clear explanation.
    I love your videos.

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

      😂

  • @he4-f2e
    @he4-f2e 3 ปีที่แล้ว +3

    Thank you for your TH-cam algorithm😌

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

    Thanks dude the exclusive part was messing with me when I started with array.

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

    Thanks man. Watching this right before my test

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

    thanks alot, this really helped

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

    excellent explanation of negative indexing in slicing section. A+

  • @EddDiaz-y7n
    @EddDiaz-y7n 9 หลายเดือนก่อน

    Learning Python- thanks for posting-enjoyed the tutorial

  • @shon7022
    @shon7022 3 ปีที่แล้ว +6

    Is there any situation where we would need to ONLY use either indexing or slicing. Or are both interchangeable?

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

    you make everything really simple to understand Bro thanks

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

    thanks i learned a lot and i hope to complete it all

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

    अतिसुन्दर,,,,,,,

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

    bro, something wrong with my code. When i copy slice=slice(7,-4), it returns str is not callable. How can I fix it?
    tk u

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

    Thank you bro❤️

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

    Excellent lecture

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

    Learnt a lot, really thanks!

  • @EM-do1yi
    @EM-do1yi 2 ปีที่แล้ว +1

    excellent tutorial !

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

    Awesome clip. Thanks that really helped

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

    The entire lesson is clear and easy to understand. But I have a small question, is it possible that the index function could be set to a character such as a space or a comma and not to a letter position in a line. For example, I am doing input, please enter the first name and last name, so that index is to the first name to a space and index to the second name from a space.

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

      You can use find( )...
      name = input("Enter ur name : ")
      hi = name.find(" ")
      slice = slice(0, hi)
      if hi == -1 :
      print (f" Your first name is {name.capitalize} ")
      else:
      print (f" Your first name is {name[slice].capitalize()}")
      😄

  • @ma.soishob9961
    @ma.soishob9961 2 ปีที่แล้ว +1

    Thanks,it was a helpful tutorial

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

    Good video bro

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

    Thank you!

  • @Daniel-du3yf
    @Daniel-du3yf ปีที่แล้ว +1

    Thanks Bro

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

    thank you for the lessons!

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

    thank you! super helpful!

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

    ez to understand. Ty!

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

    great video

  • @Mario-if5tl
    @Mario-if5tl 11 หลายเดือนก่อน

    Thanks for sharing

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

    Thanks

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

    Nice

  • @tecc9-446
    @tecc9-446 3 หลายเดือนก่อน

    nice

  • @jean-paulmpindumukandila1251
    @jean-paulmpindumukandila1251 2 ปีที่แล้ว +1

    Hello I have a question with the slice function index -4 is exclusive or inclusive. Thanks

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

      [1:-4] its exclusive, [-4:-2] inclusive

  • @raulviolante8675
    @raulviolante8675 14 วันที่ผ่านมา

    WOhooooooo BRO CODE

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

    start stop step ahh u are nice thanks

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

    INFORMATIVE!

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

    Great vídeo bro

  • @dhruvivaghela8459
    @dhruvivaghela8459 29 วันที่ผ่านมา

    u r gr8

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

    commenting because you asked so nicely

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

    Excellent!

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

    Marvelous

  • @spartanranger
    @spartanranger 3 ปีที่แล้ว

    Thanks for the video

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

    Thx!

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

    Hey, thank you!! :)

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

    thanks bro

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

    thnx bro!

  • @ГОЛОСНИК-б5б
    @ГОЛОСНИК-б5б 2 ปีที่แล้ว

    It is great !

  • @ACEthetics.
    @ACEthetics. ปีที่แล้ว

    bro is nice with the code

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

    Thank you bocd 💙💙

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

    Can you make a tutorial on pygame plzzz sir

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

    exlent tuto I apreciate

  • @不重要-c2r
    @不重要-c2r 4 หลายเดือนก่อน

    Hey Bro, I use the Google colab to program. When I'm trying to use slice function, the system told me that "'slice' object is not callable" I'm wondering why?

  • @GhostGaming-tt9tu
    @GhostGaming-tt9tu 11 วันที่ผ่านมา

    yeah but how do you reverse a sentence, without reversing the letters within
    i just get this error message that its not working. im sitting here for 30 minutes now :(

  • @thorcoder1
    @thorcoder1 3 ปีที่แล้ว

    You are great 👍👍😽👍🙏🙏

  • @oku1234
    @oku1234 3 ปีที่แล้ว

    thank you

  • @kubach2897
    @kubach2897 3 ปีที่แล้ว

    Tks bro

  • @tedchiu1433
    @tedchiu1433 3 ปีที่แล้ว

    thanks

  • @user-up6jq6qn8j
    @user-up6jq6qn8j 3 ปีที่แล้ว +1

    is your name really bro code?

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

      bruh you really asking?

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

    Why is it that when I write my code exactly as he does I get an error saying that 'sllice' object is not callable. In order to see it was not my fault, a copy and pasted the code exactly from the description and still got an error.
    I was using Google colab when I got this error but I did not get this error when I downloaded pycharm and wrote the code in there. Why?

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

    now PyCharm is no more tolerant to variables' names same as the function's.
    So rename that "slice" var into... say, "slicee"

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

    master

  • @ozba
    @ozba 3 ปีที่แล้ว

    perfect

  • @Melvishify
    @Melvishify 3 ปีที่แล้ว

    Ey bro.. thanks

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

    eDoc with the orb

  • @user-sh5zv4yf5s
    @user-sh5zv4yf5s 3 ปีที่แล้ว

    Were did you learn python

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

    Try
    Ty

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

    i didnt understand the output of funky_name = name[::2]. can someone explain to me pls, i understand that the default is 1 but i dont get the 2 and 3

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

      Basically, the number that you put after the second colon (the step) is how many indexes of the string the compiler will increment(or decrement by, if the value is negative) when slicing the string. In the case of funky_name, since the step value is 2,
      every other letter in the name is printed because the index will be going up by 2 instead of the default 1. Hope this helps.

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

    noice

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

    Thanks edoC orB

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

    shout out to people that just press the like button for bros videos, just because

  • @sheelareddy7969
    @sheelareddy7969 3 ปีที่แล้ว

    bro can you create josh clone

  • @realarchie9043
    @realarchie9043 3 ปีที่แล้ว

    Why am I getting invalid syntax

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

      It wasn't a good idea to use the name for the variable "slice" same as the function's "slice ()"

  • @tarikyassa1076
    @tarikyassa1076 3 ปีที่แล้ว

    👍

  • @neeraj4210
    @neeraj4210 3 ปีที่แล้ว

    ❤️

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

  • @tintingchen6558
    @tintingchen6558 3 ปีที่แล้ว

    Hey bro this video no Chinese cc >

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

  • @mincart9899
    @mincart9899 3 ปีที่แล้ว

    I think bro code eated alot of brocoli s

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

    Broooo

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

    youtube algorithm comment

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

    Bro

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

    hell💀

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

    t u

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

    Great Video

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

    cool

  • @TheKing-tj4sc
    @TheKing-tj4sc 10 หลายเดือนก่อน

    Thanks

  • @davelaff73
    @davelaff73 3 ปีที่แล้ว

    Nice

  • @airlanggak5391
    @airlanggak5391 3 ปีที่แล้ว

    thanks!

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

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

    Thanks

  • @AnishSaha_
    @AnishSaha_ 3 ปีที่แล้ว

    Thanks

  • @gokulc7043
    @gokulc7043 3 ปีที่แล้ว

    Thanks bro