Python For Loops - Python Tutorial for Absolute Beginners

Поделиться
HTML-код
  • Опубликовано: 22 окт 2024

Комментарии • 283

  • @brianligat2038
    @brianligat2038 Год назад +55

    I cannot recomment Mosh's tutorials enough. Easy to follow, helpful and friendly style.

  • @aliasad1392
    @aliasad1392 5 лет назад +111

    I am a new learner. And for some reason i feel it complicated dealing with loops. But i am determined. Hope so will understand it soon. Mosh you are a great teacher. God bless you.

    • @KidsLearnHTML
      @KidsLearnHTML 4 года назад +15

      Hi, I'm a high school teacher -and I COMPLETELY agree. It's like he's adding things that can distract from the learning process. For example using range instead of a regular list of let's say ["cow", "pig", " duck", "hen"] or ["baseball", "football", "swimming", "judo"]. It's kinda like a teacher using 2 or 3 terms a kid doesn't understand -to explain the FIRST term that the kid doesn't understand.

    • @mohammedalzamil7191
      @mohammedalzamil7191 4 года назад +3

      its been 8months did u get anywhere with coding?

    • @aliasad1392
      @aliasad1392 4 года назад +5

      @@mohammedalzamil7191 nah mate. Unfortunately i couldn't concentrate. Had to start my job to had less time for coding. I am sad

    • @mohammedalzamil7191
      @mohammedalzamil7191 4 года назад +3

      @@aliasad1392 man start again I started about 3 days ago and the thrill of running the program and it actually works is invaluable, look up the 4hr course on python it'll give u a good start

    • @swallowedinthesea11
      @swallowedinthesea11 4 года назад +6

      Loops are one of the most riotously difficult topics for beginners in all languages, not just Python. I found it confusing when I first began. You just have to keep practicing. 06202020

  • @invinciblenoman
    @invinciblenoman 3 года назад +70

    I believe self-learning of programming becomes easier if you start implementing your latest learned codes in small programs. such as Mosh just made in exercise. try to find small exercises for 'for loops, nested loops, with if statements. it will increase your learning pace and keep you motivated.

    • @brianligat2038
      @brianligat2038 Год назад

      I split mine into different modules to experiment with particular topics. Easy to add to without a single module getting too large and messy. My main just has a menu (2 dictionaries of options and functions). I could then add other bits like a TicTacToe and Minesweeper game.

  • @the_seahawk22
    @the_seahawk22 4 года назад +98

    I feel like reading the actual code or trying to determine what to type is why for loops are so fucking difficult to understand. Most of the time I am staring at other people’s code just overwhelmed

    • @murder8928
      @murder8928 3 года назад +7

      dude exactly, i have to write shit down

    • @OmSaiSwarupSetty
      @OmSaiSwarupSetty 3 года назад +5

      Exactly the same feeling of mine too

    • @alyanna1260
      @alyanna1260 3 года назад +2

      ahh same same:((

    • @Asterics.
      @Asterics. 3 года назад +2

      same here man, logic is so hard to mix with any other data type

  • @syedmohammedakberhussaini5620
    @syedmohammedakberhussaini5620 Год назад +32

    Dude, You made my Basics Very Strong
    print("Thank You Mosh")

  • @faridgulum1226
    @faridgulum1226 4 года назад +33

    Thank you, Mosh. I learned the parts I lacked as a beginner. I also learnt how to add int to string in print function. :)

    • @ButterCupLetsgoColts
      @ButterCupLetsgoColts 2 года назад

      you should become a hacker for the United States NSA :))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

  • @amandal8404
    @amandal8404 3 года назад +68

    this was exactly what I was looking for. it was a bit hard to follow written tutorials, so thanks for such a clear and concise one here!

  • @sabamohammadi4617
    @sabamohammadi4617 4 года назад +2

    دستت درد نکنه ماش بعد از چند تا ویدئویی که از for loops دیدم با ویدئوی شما بالاخره کار کردن باهاش رو یاد گرفتم

  • @CIMiclette
    @CIMiclette 21 день назад

    Dude you're a hero, been struggling with loops (especially nested loops) in my fundamentals of computing course in school, you explained them much more clearly than my professor, thanks!

  • @praanadhyarlagadda6413
    @praanadhyarlagadda6413 Год назад +39

    thanks so much, i have an exam.

  • @TifaS.F
    @TifaS.F 2 года назад +2

    Hello there Mosh! This is my exercise code (12:37)
    My code:
    for i in range(2, 9, 2):
    print(i)
    print('We have 4 even numbers')

    • @t3rm1nat0r4
      @t3rm1nat0r4 Год назад

      Yeah this works really well in practice, and I don't see a situation where you can't use it but he specifically said not to add the third variable in the first parenthesis

  • @HelenNPerlas
    @HelenNPerlas 2 года назад +8

    Thank you Mosh! I survived this topic. It helped a lot in my lessons on looping in Python.

  • @alexgicheha5755
    @alexgicheha5755 2 года назад +8

    Hi Mosh! You're the best Tutor.
    I am looking forward to learning more from you.
    I want to learn python for data analysis, web development, and game development.
    I welcome all the challenges, but I am passionate about becoming a Pythonista. Whatever it takes, Mosh, as long as you're my tutor, I know I'll make a great programmer like you.😘🤩

  • @smaransure2234
    @smaransure2234 2 года назад +2

    Thank you so much. I am pretty intermediate, but I never knew exactly how loops work. This video helped alot, so thank

  • @TheTitanGrimm
    @TheTitanGrimm 7 месяцев назад

    Well you have the best explanation on for loops. Most other videos I couldn’t apply to my program. Thank you.

  • @harshalnath4853
    @harshalnath4853 2 года назад +1

    first I am gonna take break in the middle of this video while learning and comment for this guy because this man deserve a huge respect because I roamed around so many videos but no one is so good as him love u man.

  • @tcpnetworks
    @tcpnetworks 4 года назад +8

    Sir - you are absolutely awesome to listen to :) Thank you for making this language so much fun.

  • @uffeheden6100
    @uffeheden6100 2 года назад +3

    Thanks! Exactly what I'm looking for where I'm in my learning curve. Great with the addons where most courses go. Cheers!

  • @narutoxtreme123
    @narutoxtreme123 2 года назад +2

    Just want to say thanks 🙏🏽. I have been using your videos along with my course work. Awesome 👏🏽

  • @emmanuelleallen
    @emmanuelleallen 9 месяцев назад +1

    I've been learning Python for about a solid 2 weeks. Self-taught. And so I wouldn't say im an "Absoloute Beginner," but I'm not far off. And this tutorial was actually very difficult to follow in regards to the expectation. IT WAS informative though, and showed me a few things i havent looked at yet, though.
    I'd reccomend the following changes for videos like this in the future, if youre using the "absolute beginner" title.
    Any concept that isnt directly related to the for loop, should also be explained in a little bit more detail. You gave a challenge that required using knowledge that wasnt included in this video. These operands "%, ==, =, +="
    These commands "if, else"
    Boolean results "True False"
    And a few other things.
    Realistically, this video is one of a series. And the title should be rightly have a series identifier on it. Like "Python for Absoloute begginer 8/20: For Loops"
    This would give the user the idea that there is likely information refrenced in this video using previous content. And builds off of *some* knowledge base. But meant for very intruductory users.
    Only sharing these things to help you and the viewers. Best of luck!

  • @md.mahedihasanhridoy3571
    @md.mahedihasanhridoy3571 5 лет назад +6

    Very nice presentation and you make coding just simple.

  • @hogrider9249
    @hogrider9249 4 месяца назад

    Thank you for these lesson, they help me a lot. I especially like the practices because they help me remember.

  • @christianwiah4526
    @christianwiah4526 Год назад +2

    Thanks, Mosh - Your lectures are simplified and easy to follow.

    • @easydatascience2508
      @easydatascience2508 Год назад

      See mine too. Easy to follow, most of the fundmental tutorials for Python and R. Source files can be found in the description of each video, by the way.

  • @BIackBoomBox
    @BIackBoomBox Год назад

    Love the example you showed with the email. Made it easier to understand

  • @Segun24-7
    @Segun24-7 3 месяца назад +1

    Thanks a lot, I think I understand loops then I see it implemented and come back to watch tutorials. I guess I am stuck in a loop myself😪

  • @Repeeeet
    @Repeeeet Год назад

    Wow!! This is awesome. I'm in a bootcamp and this was confusing. Thanks for posting this. I hipe you consider posting more recent tutorials.

  • @pookie47
    @pookie47 7 месяцев назад

    This was so helpful me to me to understand.. and like.. comprehend. thank you

  • @cornationboot8690
    @cornationboot8690 Год назад +1

    count = 0
    for x in range (2,10,2):
    print(x)
    count +=1
    print("We have {count} even numbers")

  • @vatsal_gamit
    @vatsal_gamit 5 лет назад +2

    one the best videos on the internet for loops

  • @simphiwemtshali5452
    @simphiwemtshali5452 2 года назад

    I didn't understand my lecturer thanks to you... you the best

  • @airmett8939
    @airmett8939 Год назад +1

    for x in range(1, 10):
    if x%2==0:
    print(x)

  • @zahrabolghanabadi1478
    @zahrabolghanabadi1478 9 месяцев назад

    You are the best teacher in coding❤

  • @ahmetunaldi7601
    @ahmetunaldi7601 6 дней назад

    Mosh is great for beginners.

  • @epicvoyager5938
    @epicvoyager5938 Год назад

    Thank you for the simple and quick instructions, you've been a great help!!

  • @chunyiptaxi
    @chunyiptaxi Год назад

    thanks for your clear explanation

  • @codewithelyanan6536
    @codewithelyanan6536 3 года назад +1

    I finally understand about loops in python

  • @rohitsd7732
    @rohitsd7732 Год назад

    for even in range(1,10):
    if even%2==0:
    print(even)
    print('we have 4 even numbers')

  • @neerajnegi3517
    @neerajnegi3517 11 месяцев назад

    Really easy to understand

  • @jimgraham1404
    @jimgraham1404 Год назад

    Thank you mosh. I know it’s simple and it’s perfect 😊

  • @nakshathraopillai679
    @nakshathraopillai679 2 года назад +1

    REALLY HELPFUL !!!!!!!!!!!!

  • @pallabidas5991
    @pallabidas5991 4 месяца назад

    Mosh, you are awsome ... I really learn through your videos.

  • @a.b.3030
    @a.b.3030 3 года назад +1

    Very good explained. Thank you.

  • @yourpapa6641
    @yourpapa6641 Год назад

    count = 0
    for x in range (1,10):
    if x % 2 == 0:
    count += 1
    print(x)
    print("We have " + str(count) + " even numbers")

    • @cornationboot8690
      @cornationboot8690 Год назад

      hi bro why u use using concatenation, it will just merge them together instead try using , instead of +

  • @LittleAres
    @LittleAres 2 года назад

    another way to solve the exercise could be this:
    for i in range(0,10,2):
    if i > 0:
    print(i)
    print('we have 4 even numbers')
    the result is still the same:D

  • @pcharl01
    @pcharl01 5 месяцев назад

    I was hopefully watching this would help me with my crash course in python on coursera. I'm not sure if I'm there yet.

  • @Luka_WiFi
    @Luka_WiFi 4 года назад +2

    for num in range(2, 10, 2):
    print(num)

  • @priyankadhage700
    @priyankadhage700 9 месяцев назад

    This only video helped a lot . Thanks

  • @phuongdungnguyenthi1574
    @phuongdungnguyenthi1574 2 года назад +2

    Hi Mosh, thank you so much for your video! it's so helpful. I would like to ask that could I write the code like this: for x in range (2,10,2):
    Print (x)?
    When I run my code, it's still shown the similar result.

  • @alaskachan5914
    @alaskachan5914 3 года назад +1

    thank you very much for this tutorial.

  • @ZuhayerSarfaraz
    @ZuhayerSarfaraz 11 месяцев назад

    bless you my man, bless you. Top tier crash courses out there

  • @lesyamaur7787
    @lesyamaur7787 4 года назад +2

    This was really helpful

  • @accio5557
    @accio5557 4 года назад +1

    thanks a lot mosh i am glad i found this tutorial

  • @siddiquebaloch786
    @siddiquebaloch786 4 месяца назад

    for num in range(1,10):
    print(num*2)
    if num*2 ==8:

    if True:
    print('We have 4 even numbers')

    break

  • @muhammedmustafa7685
    @muhammedmustafa7685 2 года назад

    for number in range(0,101):
    if(number % 2 == 0):
    print(number)

  • @jamonlewis6466
    @jamonlewis6466 10 месяцев назад

    Mosh you have the best tutorials on coding, but I wish, for the love of God someone would explain the syntax of the “for loop” so some sense could be made of why it’s written the way it is. I love how so much of Python correlates with the regular (English) language, but the “for loop” syntax is the most abstract & bizarrely written expression ever & NO ONE who I’ve come across that teaches python seems to think the format of the “for loop” syntax needs to be made since of for people learning python.

  • @VotiSam
    @VotiSam 11 месяцев назад

    even_number = 0
    for i in range(1, 10):
    if i % 2 == 0:
    print (i)
    even_number += 1
    print(" we have", even_number, "even numbers")

  • @nguyenloc2634
    @nguyenloc2634 3 года назад +1

    Excuse me sir ! Do you have some basic exercises in Python?

  • @sparkscomputerprogramming
    @sparkscomputerprogramming 2 года назад

    the best coding teacher in youtube

  • @MohammadMehdi_1889
    @MohammadMehdi_1889 27 дней назад

    Thank you

  • @faraic
    @faraic 3 года назад +1

    # great explaination i see why there is a million views.my code as below
    total = 0
    for i in range(1,100):
    if i%3 == 0 or i%5==0 :
    total = total + i

    print(total)

  • @tixer9786
    @tixer9786 Год назад

    I think your way of doing the exercise can be simplified to this:
    for numbers in range(0, 10, 2,):
    print(numbers)
    if numbers == (8):
    print("There are 4 even numbers")
    #This is a much easier way of doing it

  • @muhammedmustafa7685
    @muhammedmustafa7685 2 года назад

    for i in range(lengte):
    # Create a list of columns
    for j in range(breedte):
    print("*", end="")
    print()

  • @druskii90
    @druskii90 2 года назад

    Thank you for explaining for loops very clearly, idk I've been struggling to understand them and this helped so much! Sub earned!

  • @HimanshuSharma-oy9ss
    @HimanshuSharma-oy9ss 4 года назад +4

    Hello mosh ! I'm taking your free 6 hours python course. But when i tried to solve the 'sum total of prices' problem , even when i typed exactly what you did in the video, my result were iterative instead of a single integer value ( the actual expected sum total ). Is there any settings that i have to change in pycharm ?

    • @Ohamskillua
      @Ohamskillua 2 года назад +3

      you should check for capital letters make,and also check for indexation,python is case hsensitive

  • @medhbb6315
    @medhbb6315 Месяц назад

    Thanks ❤

  • @mohammadanarul624
    @mohammadanarul624 5 лет назад +2

    thank you sir..

  • @iyazbhat8213
    @iyazbhat8213 4 года назад +2

    In which VSCode Extension you're running code, if it's other then Terminal.

  • @benlong1080
    @benlong1080 3 года назад

    Hey, awesome and informative vid! I like the challenges included. But quick question.
    I ran my code:
    for even_num in range
    (1, 9, 2):
    print(even_num)
    print("We ......")
    And it was successful. I wish I would have written the more sophisticated way, but can you tell me how mine would not function the same ultimately?
    Thanks!

  • @muhammedmustafa7685
    @muhammedmustafa7685 2 года назад

    for i in range(1, 11):
    print(tafel, 'x', i, '=', tafel*i)

  • @BettoRaite_
    @BettoRaite_ 2 года назад

    iterables are the things that can launch the for loop and make the sequence of repetitions
    #I don't know if it's the right definition, but this is how I interpretered the meaning of iterables

  • @freehappymeal
    @freehappymeal 2 года назад

    I like the way you explain this concept. It helped to see what was going on in the nested loop.

  • @mdbelalhossainsanto6523
    @mdbelalhossainsanto6523 9 месяцев назад

    #Printing even number
    for num in range (2,10,2):
    print (num)
    print("we have 4 even numbers")

  • @Kiros-r1q
    @Kiros-r1q 4 месяца назад

    Thanks

  • @zbynk810
    @zbynk810 2 года назад +1

    Thanks for this tutorial, but is it possible to make a loop for the numbers (for example: 0, 1, 2, 3, 4), but starting with 43? (for example 43, 44, 45, 46, 47)

    • @neveyom8869
      @neveyom8869 2 года назад +2

      u can if you do this
      for I in range(43,50,1)
      btw I am not professional i am 12 but this should work

    • @zbynk810
      @zbynk810 2 года назад +1

      @@neveyom8869 thanks, I'm just 2 years older than you, so you're not alone

    • @neveyom8869
      @neveyom8869 2 года назад +1

      Sure (⁠ノ⁠◕⁠ヮ⁠◕⁠)⁠ノ⁠*⁠.⁠✧

  • @mr.transformer1299
    @mr.transformer1299 7 месяцев назад

    Good day sir,
    At
    5:15- I tried
    Successful = True
    for number in range (3):
    print(“test”)
    print (“Successful”)
    if successful:
    break
    And I got the same result of;
    test
    Successful.
    Please what’s the implication of the difference in the positioning of the 4th and 5th line i.e
    The print (“successful”) and if successful?
    Thanks sir.

  • @innemannen
    @innemannen 10 месяцев назад

    Great video

  • @daviddean5512
    @daviddean5512 11 месяцев назад

    why for the final example can't you just write
    for x in range(2, 10, 2):
    print(x)
    print("We have 4 odd numbers")
    Is it because if the interval was something like (2, 198534, 2) you could write the wrong amount

  • @monttyy4879
    @monttyy4879 2 года назад

    Your channel is helping me so much .. my teacher is so trash and doesn’t tell us shit and just expects us to understand from reading his examples

  • @LifeWithSeb99
    @LifeWithSeb99 4 года назад +2

    My solution is slightly different, have a look:
    h = int(input("Enter Number: "))
    y = range(1, h)
    for x in y:
    if x % 2 == 0:
    print(x)
    z = (len(y)) // 2
    print("we have ", z, " even numbers between 1 and ", h)

    • @swallowedinthesea11
      @swallowedinthesea11 4 года назад +1

      Good, good! I like it when people take the time to find unorthodox ways to solve problems. It trains your mind. 'Be like water' ~ Bruce Lee.
      06202020

    • @drei4641
      @drei4641 4 года назад +1

      The fact that I was able to mostly understand this as a full beginner makes me proud of all the thinking I did while learning

  • @ashleyyy8036
    @ashleyyy8036 3 года назад +7

    sorry to disturb, but I have a stupid question that bogged me down: I see no links between the variable successful and the for loops, so why the statement "successful = True" will affect the correctness, or the execution of the for loops?

    • @brentdan68
      @brentdan68 3 года назад +1

      If that if statement is false it would not execute it

    • @dharshinia9378
      @dharshinia9378 3 года назад

      an "if" statement will only occur if the given statement is True.

  • @bishakhadeb1800
    @bishakhadeb1800 4 года назад +1

    Thanks Sir. You're the best :)

  • @itchyfungus8481
    @itchyfungus8481 2 года назад

    If you're a beginner it's not you, it's the teachers. They teach how they were taught and so we live in this world. The issue is no one is breaking things down. They're all just diving in and repeating information that in truth they may not even know why to use a function in the order they used it. They just know it works. So the issue is, why to use a for loop and why to use range? why to combine these methods. Because once you understand why, then you can understand limits, and also combinations of those limits. So if anyone knows why certain combinations work and why others don't please feel free to direct me to the correct source of information on where I can learn this.
    Example:
    Topic - For loops
    What is a for loop
    How to use a for loop
    why a for loop only works in etc why it doesnt

  • @anumthkl9
    @anumthkl9 2 года назад

    Dear mosh why you are storing the variable successful =True,what if its not there....
    thanks'

  • @kevinflynn4867
    @kevinflynn4867 2 года назад

    Thank you Sir ! Your video were very helpful

  • @jemjemcorner3522
    @jemjemcorner3522 4 года назад

    thanks mosh

  • @dawidmarszaek3106
    @dawidmarszaek3106 2 года назад

    How did you get this nice-looking Output window? I am looking for it for so long and the only one I have got is a terminal window with all of the paths, ending messages which are distracting. I would be grateful for telling me how to open this Output view.

  • @karimabrini
    @karimabrini 6 лет назад

    Thanks Mosh easily explained

    • @karimabrini
      @karimabrini 6 лет назад

      @@programmingwithmosh beginner

  • @maryharrer2603
    @maryharrer2603 2 года назад

    My Python book is only teaching me math. YOU are teaching me Python. Thank you.

  • @nerdifiedish1334
    @nerdifiedish1334 2 года назад

    heres the answer for the exercise without looking:
    for x in range(1, 10):
    if x%2 == 0:
    print(x)
    print("we have 4 even numbers!")

  • @muhammedmustafa7685
    @muhammedmustafa7685 2 года назад

    Fizz = 3
    Buzz = 5
    FizzBuzz = Fizz * Buzz

    for a in range(51):
    if a % FizzBuzz == 0:
    print('FizzBuzz')
    elif a % Fizz == 0:
    print('Fizz')
    elif a % Buzz == 0:
    print('Buzz')
    else:
    print(a)

  • @muhammedmustafa7685
    @muhammedmustafa7685 2 года назад

    if (getal % 3 == 0):
    print('Deelbaar door 3')
    else:
    print('Niet deelbaar door 3')

  • @ganeshofficialyoutupechann4768
    @ganeshofficialyoutupechann4768 4 года назад

    thank you sir

  • @KamaraKabbahsorie
    @KamaraKabbahsorie 6 месяцев назад

    That's what I expected ❤

  • @eliuddelacruz5353
    @eliuddelacruz5353 Год назад

    I’ve looked everywhere online and I can’t find anything that explains for loops or while loops well enough for me to understand. Why didn’t the string “Attempt” print out three times or the word successful? Also what does the word number do what’s its purpose? Where did you get the word from? Why that word?

  • @dineshpokala2939
    @dineshpokala2939 4 года назад +1

    Perfect

  • @muhammedmustafa7685
    @muhammedmustafa7685 2 года назад

    i = 0
    while(i < 30):
    print('Hallo')
    i = i + 1

  • @ocraking
    @ocraking 6 месяцев назад

    Great tutorial, many thank yous haha ;)

  • @thelolimaster359
    @thelolimaster359 Год назад

    So the value of count updates globally because for is not a function?

  • @souravde6116
    @souravde6116 3 месяца назад

    One this is not clear what is difference between string and formated string that you used write many times inside printf()?