Python email slicer exercise 📧

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

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

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

    email = input("Enter your email: ")
    username = email[:email.index("@")]
    domain = email[email.index("@") + 1:]
    print(f"Your username is {username} and domain is {domain}")

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

      Thank you

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

      i prefer partition over index slicing but for the given logic is useful tho.

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

      It is a perfect and superuseful excersise but what you did at the last by typing email.index("@") twice is a bad practice btw cuz u are calling the same fuction twice , and this is a bit hard to the memory

    • @Computer-v5e
      @Computer-v5e หลายเดือนก่อน

      Thank you master bro

  • @kashmirtechtv2948
    @kashmirtechtv2948 วันที่ผ่านมา

    you are amaizng

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

    You really make coding look easy. This is coming from a guy who just finished your C course :D

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

    Great video ❤

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

    Thank you. Very helpful
    We can also use str.split function as below
    email = input('Enter your email address: ')
    username, domain = email.split('@')
    print(f'Your username: {username} and domain: {domain}')

    • @Camaron242
      @Camaron242 6 หลายเดือนก่อน +2

      That’s what I thought would’ve been the most straightforward method

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

    I just watched after coming back from the the college. You makes the so beautiful. I hope to master python just after m done with JavaScript. Your JavaScript lesson are also the most beautiful part. I love it brother. Thank you!

  • @migukau
    @migukau 5 หลายเดือนก่อน +1

    Its important to note that the second method is less efficient because you are calling the index function twice instead of just calling it once.

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

    Love you man!!!! You inspire us all!!!!

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

    thank you bro

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

    Just use the in-built python fuction which is called as ".partition()". What this basically does it, you specify the string object lets say x="This line of code will partition the word banana into 3 different words in a list". Then give another listobject lets say "a". There the code would go like this.
    >>> a=x.partition("banana")
    >>>print(a)
    ["This line of code will partition the word","banana","into 3 different words in a list"]
    This is very useful for real life applications such as machine learning, keyword identifying, spelling mistake checking and alot more.
    The return type of this partition is a list of strings where the strings before the word "banana" is a part of string followed by the partitioned word "banana" and then the rest of the string after banana into a sperate one. The length of the separation is always 3 as words before the given word and then word itself and the words after the give word.
    Partition only works for string datatype and nothing else. So don't forget to give the given word inside in quotes, you could also store the string in a separate object and specify it in inside the parenthesis without the quotes.
    Hope this gave an alternate method for the same solutions, stay programming always 😎😎

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

    Thank u Bro

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

    I understand java and data structure after watching your vids. Man you are legend. Can you crate tutorial about spring boot and rest api I know you are good at java

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

    Hello. Please make a full course on Springboot framework. Microservices Docker.

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

    Thanks Legend

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

    Hi bro code could you make a SQL video please have a nice day ;)

  • @gian-mm9kr
    @gian-mm9kr ปีที่แล้ว +4

    Hey, could you explain to me the difference between the .index and the .find ?

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

      the difference is that .index will have an error when it’s not able to find what it’s looking for and .find returns a -1 if not able to find what it’s looking for. Other than that they do the same thing where they return the lowest number where the character is found.

    • @jomon-bq8hz
      @jomon-bq8hz 3 หลายเดือนก่อน

      @@h4560 thank you 💡💡

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

    took me a while to figure this out

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

    we can also use 'find' method instead of 'index'

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

    python, gangsta language LOL

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

    what microphone and keyboard you use?

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

    Why not str.split()?

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

      LOL I was thinking the same.

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

    Less lines of code makes the program runs faster?

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

    Bro, do you have a discord server?

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

    Can remove 2 more lines if you want 😂

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

    email = input("Enter your email: ")
    print(f"Your username is {email[:email.index("@")]} and domain is {email[email.index("@") + 1:]}")
    less lines of Code

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

      f-string: unmatched

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

    just to add to your already excelent content, if i may:
    you can also achive the same in the follwoing way:
    email = input("enter your email: ")
    user_name, domain_name = email.split("@")
    print(f"your username is {user_name} and your domain name is {domain_name}.")
    * this only works if you know ahead of time that you're going to recieve two strings after the split.

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

    I just wanna ask what's the purpose or function of +1 ?

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

      so that the @ itself shouldn't be printed because when printing domain the @ becomes inclusive

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

    Hello bro! I'm a beginner programmer and just started learning java a month ago. I'm not very good at it and I want to improve. I have bad logic and always cant think the other way around and stuck on a method. Is there anyway for me to improve?

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

      Just use the in-built python fuction which is called as ".partition()". What this basically does it, you specify the string object lets say x="This line of code will partition the word banana into 3 different words in a list". Then give another listobject lets say "a". There the code would go like this.
      >>> a=x.partition("banana")
      >>>print(a)
      ["This line of code will partition the word","banana","into 3 different words in a list"]
      This is very useful for real life applications such as machine learning, keyword identifying, spelling mistake checking and alot more.
      The return type of this partition is a list of strings where the strings before the word "banana" is a part of string followed by the partitioned word "banana" and then the rest of the string after banana into a sperate one. The length of the separation is always 3 as words before the given word and then word itself and the words after the give word.
      Partition only works for string datatype and nothing else. So don't forget to give the given word inside in quotes, you could also store the string in a separate object and specify it in inside the parenthesis without the quotes.
      Hope this gave an alternate method for your question, stay programming always 😎😎

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

    Hey, where can I practice this ?
    On github or ?

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

    my solution:
    username, domain = email.split('@')

  • @MAT.H404
    @MAT.H404 2 ปีที่แล้ว

    email = input("Enter your email: ")
    name = email
    email = email.find("@")
    name = name[email+1:]
    print(name)

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

    Comment

  • @ananyahc8589
    @ananyahc8589 4 หลายเดือนก่อน +1

    email.find("@") does the same job as email.index("@")