9. For loop [Python 3 Programming Tutorials]

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ส.ค. 2024
  • The topic which I will explain to you today is about “for statement” also known as “loop statement”, “for” loop, “while statement”, how to create “for” loop, why “for” loop is used.
    Exercise: github.com/codebasics/py/blob...
    Topics that are covered in this Video:
    0:00 Overview
    2:55 Create a for loop (Syntax of for loop)
    6:53 Why for loop is used?
    7:02 Use of range() function
    18:51 While statement
    Do you want to learn technology from me? Check codebasics.io/ for my affordable video courses.
    🔖Hashtags🔖
    #forloopinpython #pythonforloop #tutorial #loopinpython #python #pythonloops #pythonloops
    Next Video:
    10. Functions [Python 3 Programming Tutorials]: • 10. Functions [Python ...
    Website: codebasics.io/
    Facebook: / codebasicshub
    Twitter: / codebasicshub

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

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

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

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

      I am unable to understand the today class

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

    Dear sir, I am watching the tutorials from last 7 days. The way of explaining the concept with example is very much effective and easy to get the things..

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

    I watched different tutorials in loops, and this is the best video I have ever seen! Easily understandable!

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

    I watched different videos from other tutorial regarding loops and this one I understand the most. Thank you!

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

    Here is the link of exercise along with the solution, please work on it as it will make your learning solid: github.com/codebasics/py/blob/master/Basics/Exercise/9_for/9_for_exercise.md

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

      Page not found 404????

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

      Page 404

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

      Visit exercise from function video and then check full directory of exercises! You will find every video exercises!

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

      if i open the link its showing page not found

  • @codebasics
    @codebasics  5 ปีที่แล้ว

    Learn data science with python and pandas: th-cam.com/video/CmorAWRsCAw/w-d-xo.html

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

    very useful assignments sir... they are definitly developing logic... most of time i use solution due to lack of logic.. but still it is useful... thanks for taking efforts for us....

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

    thank you for the excellent content and work!

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

    great channel to learn data science skills with projects.

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

    Appreciate it, bro. Thanks

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

    well you have created amazing tutorial till now, few months back I started with C and now these tutorials are really good, i think i will be watching whole play list.......

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

      Great. I wish you all the best prajwal 😊👍

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

    you explain in a great way with those explanations beside the code is awesome.Thanks

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

      Glad it helped!

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

    Superb explanation sir ☺️😊

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

    sir your videos are really very great

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

    Hello sir .. thank you... your videos are really helpful ..I have a boudt. When I run a program in pycharm it is showing "some file is running parallel. " and a dialouge box showing " stop running any way" or " cancel". Please help me with this

  • @mdasif-ze7bc
    @mdasif-ze7bc 2 ปีที่แล้ว +2

    Sir without declaring the items how you item put in print plz clearfy this doubt

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

    Can I give while condition and another condition ime giving 2 conditions using and operator just like we do in if statement

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

    if i want to print n numbers so what should I give the range ?

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

    thnks sir.
    incase if you want to print only odd number then use i%2!=0

  • @-GRajesh
    @-GRajesh 4 ปีที่แล้ว

    Good Morning Sir. Is this same for notepad? What you are explaining in pycharm and python 3

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

    the printing of square of only odd numbers
    this approach is also effective :
    for i in range(1,10,2):
    print(i*i)

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

    Awesomeeeeeeeee

  • @D4nte-RN
    @D4nte-RN ปีที่แล้ว

    Hello,
    Thank you, very much for your involved with teaching us with very simple and understanding way!
    According your suggestion, aftera watched your tutorial I switch to exerecises and I tried to doing myself.
    I have a problem with your 3-rd exercises and solution. Why in the code there's:
    "month = -1" and "month != -1" and whay even I put here value "month = -10" and "month != -10" it sill working correctly?

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

    Hi, in exercise number 5, i tried below code and it seems working and giving same result. Not sure why need 2 range functions in the solution. Please enlighten me. Thanks, and as always more power to your channel. It's very helpful...
    Star = ""
    for i in range(1, 6):
    Star += "*"
    print(Star)

  • @basebuiltclasses1401
    @basebuiltclasses1401 5 ปีที่แล้ว

    Nice sir

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

    for i in range(1,6):
    s=i**2
    if s%2==1:
    print(s)
    #output :
    1
    9
    25

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

    2:09 "...what if your list had like hundred items in it. If you start writing all of these, you'll become granddaddy by the time you're done writing this." 🤣😂🤣😂
    Great and informative tutorial, with a hilarious teacher. Thank you.

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

    great

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

    with the same code my console is printing all the outputs like sum of first than second than third and so on and not like you have shown the output

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

    where can I get more challenging exercises. you are such a great teacher I need harder problems

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

      hackerrank and other websites..

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

    Hello Amazing Sir, the exercise files aren't working, would be huge favor if you take-care of it.

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

    The "continue " code ....wow! i=i+1 very important!

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

    Hi sir this is krishna, daily iam following these videos but for loop video it is a bit of confusion while iam practicing on pycharm.
    (while, continue, break point)

  • @khemrawat4144
    @khemrawat4144 4 ปีที่แล้ว

    hi Sir , i have one doubt in example of for loop with continue statement when we use conitnue statement else statement is not required?

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

      Nope. When you continue the control flow goes back to next iteration in for loop and you don't need else

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

    how do i check if my code is good and it is the optimised code or not? for instance
    for the one of the practice example:
    1. This solution is given by dhaval (codebasics)
    month_list = ["January", "February", "March", "April", "May"]
    expense_list = [2340, 2500, 2100, 3100, 2980]
    e = input("Enter expense amount: ")
    e = int(e)
    month = -1
    for i in range(len(expense_list)):
    if e == expense_list[i]:
    month = i
    break
    if month != -1:
    print('You spent',e,'in',month_list[month])
    else:
    print('You didn\'t spend',e,'in any month') month_list = ["January", "February", "March", "April", "May"]
    expense_list = [2340, 2500, 2100, 3100, 2980]
    e = input("Enter expense amount: ")
    e = int(e)
    month = -1
    for i in range(len(expense_list)):
    if e == expense_list[i]:
    month = i
    break
    if month != -1:
    print('You spent',e,'in',month_list[month])
    else:
    print('You didn\'t spend',e,'in any month')
    2. My solution is:
    expense_list = [2340, 2500, 2100, 3100, 2980]
    month_list = ['jan', 'feb', 'march', 'april', 'may']
    expense_amount = int(input('please enter an amount number: >>> '))
    for i in range(len(expense_list)):
    if expense_amount == expense_list[i]:
    print (expense_list[i],' was spent in', month_list[i])
    break
    else:
    print('expense amount is not available')
    please help me how can I check a good is optimized code.?

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

      Awesome karthik chekuri, code looks very good

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

      This code is not working

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

    Thankyou, i couldn't still do the exercises tho;/

  • @gurpreettata
    @gurpreettata 4 ปีที่แล้ว

    well explained

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

      Gurpreet, I am happy this was helpful to you

  • @MrPrudhvisai
    @MrPrudhvisai 4 ปีที่แล้ว

    How for loop is terminated if we write break statement inside the if condition, i thought for loop will break only if break statement is under for loop condition. please elaborate this

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

      i think ,it breaks the execution from only if_else condition. since there no other condition inside for loop, execution gets terminated

  • @K-mk6pc
    @K-mk6pc 4 ปีที่แล้ว +1

    sir can you make a new video on for loop because i am watching every videos in series but this is more complifated it seems '

    • @codebasics
      @codebasics  4 ปีที่แล้ว

      Kiran, I have Hindi channel too. Codebasics Hindi. Watch tutorials there. You might be able to understand better as o have new and better videos there

    • @K-mk6pc
      @K-mk6pc 4 ปีที่แล้ว

      @@codebasics
      Sir thank you soo much basically my mother tongue is Kannada Anyways I will look through it sir can you provide me your contact details??? BTW I wish to make my career in data science soo i thought for asking you as a matter of reference
      Tq

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

    Idk u could use c# for that

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

    How does python know that "item" refers to the numbers in the list if it isnt written as a variable? Does it automatically assign the numbers as "item"?

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

      not only numbers,An "item" is a general term that can refer to any object within a collection.

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

    Revise for loop exercise video description

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

    In the solution for the exercise for the topic, line 64 says 'print("You....' but it should say 'print(f"You...'. Just a minor thing in an otherwise brilliant series.

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

    John 15:11-14 (KJV) These things have I spoken unto you, that my joy might remain in you, and that your joy might be full.
    This is my commandment, That ye love one another, as I have loved you.
    Greater love hath no man than this, that a man lay down his life for his friends.
    Ye are my friends, if ye do whatsoever I command you.

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

    😘

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

    Good explanation, but at 02:15 .... How do you know we aren't already grandfathers?? 😁 Mature people reskill too you know 😂😂

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

    with the below code I am getting this output . Can you help
    exp = [2340,3455,4500,2344,2133]
    total=0
    for i in range(len(exp)):
    print('Month:',(i+1),'Expense:',exp[i])
    total=total+ exp[i]
    print('total exp:',total)
    output:
    Month: 1 Expense: 2340
    total exp: 2340
    Month: 2 Expense: 3455
    total exp: 5795
    Month: 3 Expense: 4500
    total exp: 10295
    Month: 4 Expense: 2344
    total exp: 12639
    Month: 5 Expense: 2133
    total exp: 14772

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

      Write the last print statement out of the for loop

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

    in 5:47, is "item" a keyword used with for loop?

  • @talhakhan-ht6hj
    @talhakhan-ht6hj 2 ปีที่แล้ว

    man this guy loves his monthly expenses XDXD

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

    6:58

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

    Sir, I am running the same code as you created.
    but I am getting this :
    Month: 1 Expense: 200
    Total expense is: 200
    Month: 2 Expense: 100
    Total expense is: 300
    Month: 3 Expense: 350
    Total expense is: 650
    Why 'Total expense is' repeating?

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

      It is happening because you indented the final print command, remove the indentation to remove the print command from the for loop

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

    Hindi WALI video kha hau

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

    Granddaddy hha

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

    why my total showed to me like this
    "C:\documents\python projects\venv\Scripts\python.exe" "C:/documents/python projects/for loop.py"
    month 1 expense 2340
    month is 2340
    month 2 expense 2500
    month is 4840
    month 3 expense 2100
    month is 6940
    month 4 expense 3100
    month is 10040
    month 5 expense 2980
    month is 13020
    Process finished with exit code 0