#21 Python Tutorial for Beginners | For Loop in Python
ฝัง
- เผยแพร่เมื่อ 11 ก.ค. 2018
- Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-spring-cloud
Udemy Courses:
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
Java For Programmers:- bit.ly/javaProgrammers
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusko.com/
Instagram : / navinreddyofficial
Linkedin : / navinreddy20
TELUSKO Android App : bit.ly/TeluskoApp
In this lecture we are discussing about:
#1 break
#2 continue
#3 pass
In Python, break, continue, and pass are control flow statements that are used to
alter the normal flow of execution in a loop or conditional statement.
#1
break: The break statement is used to terminate a loop prematurely when a certain condition is met.
Once the break statement is encountered inside a loop, the loop is immediately terminated and the program continues
with the next statement after the loop.
for i in range(1, 6):
if i == 3:
break
print(i)
output:
1
2
#2
continue: The continue statement is used to skip the current iteration of a loop and move on to the next iteration,
without executing the remaining code in the loop for the current iteration.
for i in range(1, 6):
if i == 3:
continue
print(i)
output:
1
2
4
5
#3
pass: The pass statement is a placeholder statement that is used to indicate that no action should be taken. It is often used
as a placeholder when writing code that will be filled in later.
for i in range(1, 6):
if i == 3:
pass
else:
print(i)
output:
1
2
4
5
Github :- github.com/navinreddy20/Python-
Python for Beginners :- bit.ly/3JOLQhl
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com - วิทยาศาสตร์และเทคโนโลยี
for i in range(1,500):
if i**2
for i in range(1,500):
if i**2
bro can i get explanation
@@shivaprasadbh6013 after getting all the posible output loop will break help us to come out from the loop..... otherwise it will check until the condition become false
@@BibekGhoshh1 the code does the same even without break in this case right?
Ooh yeah got it! You're right without break there's increase in cost in terms of time. Thanks ✌️
from math import sqrt
for i in range(1, 500, 1):
a = int(sqrt(i))
if a == sqrt(i):
print(i)
Hey Navin, you have explained the for loop in a very simple and easy to understand manner for a beginner. Thanks a lot.
Yeah I saw code with Harry’s video on this topic,he’s really made a hash of it
sorry to be off topic but does anyone know of a way to get back into an Instagram account?
I was dumb forgot the password. I would appreciate any assistance you can give me
@Randy Elliott instablaster =)
@Shepard Lucian i really appreciate your reply. I got to the site thru google and I'm waiting for the hacking stuff now.
Looks like it's gonna take quite some time so I will reply here later with my results.
@Shepard Lucian It did the trick and I actually got access to my account again. Im so happy:D
Thank you so much you really help me out :D
Man I love your tutorials. You are using understandable words for beginners. A lot of people teaching coding out here are using some terminolgy that a beginner can't even understand.
Viewing at 0.75x
True😂😂
me at 2x...😅
It makes it so Easy to learn when there is a playlist instead of 1 six hour video
for i in range(1,50,1):
import math as m
if int(m.sqrt(i))==float(m.sqrt(i)):
print(i)
could you explain it plz !
@@rishabhsharma3908 it will print the square of all numbers from 1 to 50
@@rishabhsharma3908 in if block, it will check square root of all number in both int and float..
lets suppose int(sqrt(4)) == float(sqrt(4.0)) but int(sqrt(5)) != float(sqrt(5.0)) because in int case , the result will be only 2 but in float case, result will be like this 2.23606797749979 which is not equal.
nice one Rishabh, as we can also have it without "import"
@@rohitn6910 how?
import math
for i in range(1,500):
a=math.sqrt(i)
if i%a==0:
print(i, end=' ')
your code is correct and same my code
Thanks the code help me.... i have been on this for more than 3hrs but i got the hint fro your solution.
Can we do it without using math library...????
@@nmewar yep....
for i in range(1,500):
for x in range(1,25):
if i/x==x:
print(i)
i+=1
print()
@@nmewarmaybe
It's been two years but still I am learning from your page.
Thank you so much Naveen Sir🙏
# Print all perfect Square numbers between 1 to 500.
# Note : for efficiency of program we have to break the loop to avoid 500 iteration. Observe this by using debug. Post 22 iterations if we dont break the loop it does unwanted
477 iterations and increase CPU cycles.
for i in range(1,500):
if (i**2
Few reply are also supportive...
this one is the best solution....Thanks!!
yes this is efficient program
we can take iteration upto 23, as 22^2 is less than 500
it's a very useful trick, but in general, if you have to check if a given number (x) is a perfect square number or not then how you would proceed?
Solution to quiz question:
# To print perfect squares between 1 to 500
# Using for loop
from math import*
for i in range(1, 500):
if int(sqrt(i)) ** 2 == i:
print(i, end = ' ')
# Using while loop
from math import*
i = 1
while i
Name error aa raha h sqrt kya kru?
for i in range(50):
a = i * i
if a
@@Codeequest It's at the end of the video around last 10 seconds
Alternative solution
from math import sqrt
for num in range(1, 501):
if sqrt(num).is_integer():
print(num)
@@bernardkimemia9471 for i in range(1,501):
if (i*i
Thank you! I didn’t understand this at all and now it seems clear. Great teacher!
for i in range(1,500):
from math import sqrt
root=sqrt(i)
if int(root+0.5)**2==i:
print(i)
Why did u print that fourth command ; if int( root + 0.5)**2==i .
Why is that 0.5 needed ?
u r great sir ur way of teaching is just incredible
using Math Function:
import math
for i in range(1,501):
sq=math.sqrt(i)
if i%sq==0:
print('The Prefect Square root of number',i,'is',sq)
-----------------------------OR-------------------------
without Using Math Function:
for i in range(1,501):
sq=i**(1/2)
if i%sq==0:
print('The Prefect Square root of number',i,'is',sq)
thaks bro u also clear my doubt
You are the best teacher cause a guy like me found your videos interesting as I'm a civil engineer.
Thank you so much Navin! I totally appreciate the pace and thoroughness of your videos. I'll be watching!
import math
for i in range(1,int(math.sqrt(500))):
print(i*i, end=" ")
This is perfect
perfect code with minimal complexity :-)
while running it is not showing 484
please tell me why?
@@riteshjat108. Here range means up to the value but not include that value that's why.
@@sandeepkumar3866 484 is very far from 500. What is the range you are talking about, I am not getting it.
i=1
while i
Anna..... you are awesome!! No one can explain things this clearly!!
thats so mch btter teaching than my school teacher i have final exams coming this really helped me a lot. i had no idea of loops. i dont know why i had not seen you videos before
i = 1
while i**2
Nice
very easy ...the same 4rm the lesson...thanks sparta...
Not working
you didnt use the for looooooooop!
Sirrr thankyou soooo much you are building humans future...
Your teaching style and every thing is superb.... keeep it in pro level sir....god bless you... #2020👏🙏
Amazing sir..this cleared all my doubts!! Thank you so much 🙏
There's so many videos for the basic python concepts, but I finally found someone who talks fast. When people talk too slow, it makes me nervous and agitated because I feel too much anticipation for what they're about to say. I have too much time to insert my own thoughts and it becomes harder to listen.
When someone talks fast enough, the information is denser. Then I can relax and absorb.
Fast talkers are soothing
i was following codewithharry python tutorials,and i didnt get the for loop concept explained by him,but thankyou navin for explaining it much more clearly and simply
Same 👍
plz dont comparmise
Same bro what a coincidence
Same here
Same
for i in range(100):
if i*i
it is correct but it's better to add
else:
break
statement also ,other wise your code will run unnecessarily
you are a great tutor and any level of the guy can understand. Thanks for sharing your knowledge.
you are teaching in a way that listeners can really enjoy coding .Thank you so much Navin.
of all the tutorials, yours are the best. i understand everything more than i do in class. thank you so much.
asli dakait boltee
from math import *
for i in range(1,501):
a=sqrt(i);
if(i%a==0):
print(i);
In range( ), when we are going in descending order, I realized the first number is included and the last number is excluded, just like when we go in ascending order. Nice to learn that as well.
Thank you so much sir.....ur way of teaching makes the thing more simpler :)
Thank you so much navin. My small suggestion after completion of video ur giving some home work we are ready to do tat work my request is in ur next video plz tell me tat ur answer for that question we will also able to know tat answer & if someone did mistake also tey will rectify. Not someone i am also one to do mistakes i am also able to rectify
Previous video homework is the example for next video
@@msrikavya9651 where is that
please help i cant find it
Check out 100 days of code by Dr. Angela yu on udemy or app brewery. I'm learning from she teaches everything step by step. I'm sure you will get from 0 to a professional python developer after this course
import math
for i in range(1,500):
perfect_square = pow(i,2)
if perfect_square
Thanks for putting the solution in the comments 😅
Sir you came in clutch for me I have my practical test tomorrow and I got to know about it today Thank you sir
thank you so muchhhh, i hope u're having a great journey!
I really enjoy the way you teach; I understand the concept easily.
from math import sqrt
for i in range(1,501,1):
a = sqrt(i)
if(i%a == 0):
print(i , end="")
Can you please Help me here
# It should print found or not found...
arr=array('i',[5,7,9])
print (arr)
k =int(input('Enter the value to search'))
for i in arr:
if k==i:
print('value found')
break
else:
print('value not found')
I love your way of explaining,as you first do it wrong,then tell us the write method.
Thank You 😀😀
Sir you are the best python tutor I have seen till now
from math import sqrt
for i in range(1,501):
if sqrt(i)==int(sqrt(i)) :
print(i)
for i in range(1,501):
print(i*i)
try this one your code is not giving the square of last (500)
Solution of the question at the end:
import math
for i in range(1,51):
if math.sqrt(i) - (math.sqrt(i)//1) == 0:
print(i)
from math import sqrt
for x in range(1,500):
if sqrt(x) == int(sqrt(x)):
print(x,end=" ")
Sir u r awsm i mean really , i print a pattern by my own first tym after learning two languages before this... Thank you sir for such wonderful tutorials.. 🤗🤗
ans:
import math
for i in range(1, 501):
if math.sqrt(i) % 1 == 0:
print(i)
Superb
Not working
after % their will be i maybe
Thanks a lot for this wonderful series, sir. It's easy and interesting. I have recommended it to my colleagues as well. They also love it.
Thank you!!! Lots of doubts on this loop disappeared. Thank you sir☺️
Thank you navin sir ...I was not getting that why the string in for loop is printing character one by one...just like you told by giving the example of your name...but u explained it so well...that now my confusion is all clear . So thank you so much sir...😊
The answer to this quiz question is in the next video.
for i in range(1, 500):
i = i ** 2
if i >500:
break
print(i)
Got this after trying it for couple of hrs :)
import math
for i in range (1,51):
square = i ** 2
print(square)
similarly:
import math
for i in range(1,501):
if math.sqrt(i) % 1 == 0:
print(i)
@@vaibhavbopte9970 what is import math? Is it the same to c lang lib math.h?
@@kohlbovee7592 can u please explain me the functioning of if line clearly? I am a bit confused 😕
import math
i=1
while i
Thanks a lot This was really helpful.
I was searching all other places to learn some of these, then I found this and right when I saw the video I immedietly Subscribes and liked the video I think everyone else should subscribe and like and share.
Keep Up The Great Work!!!
this is absolutely amazing.Thank you!
answer is:
for i in range(1, 501, 1):
if i**2
I feel it's not right to eliminate that one from the 500 even if it gives you the same result :)
how can people dislike this😲😭😔...you are sooo amazing sir...🥺❤️
yo ..army!!
You are fantastic. Born instructor!
Best explanation of for loop. Will never get confused. Thankyou so much
import math
for i in range(1,501):
if(i**2
Why we are printing i**2??? Pls explain it..
** indicates power of , start from initial vedios
We dont need 'import math' here
It is wrong see the question b/w 500 not 501
@@varsinisivabalu9245 it means ** power so we are squaring it
import math
for i in range(1,501)
X=int(math.pow(i,2))
Y=int(math.sqrt(x))
if y==i and x
for i in range (1 ,23):
print ("i**2)
i think this is simpler
@@aryaveergupta4269 Ofcourse 👍🏻👍🏻 , that was me one year ago 😅.
i would love if you did loop over more complicated data structures such as dataframe.. nice video
I have been trying to understand this loop for years and today i understood it fully. Thanks for making this simple 😊
We are enjoying this series!!!!
Can you please Help me here
# It should print found or not found...
arr=array('i',[5,7,9])
print (arr)
k =int(input('Enter the value to search'))
for i in arr:
if k==i:
print('value found')
break
else:
print('value not found')
You explain so well ! Thanks !
awesome man..it directly hit my mind and understood instantly
I am taking a python class and your videos is helping me a lot. Thank you so much for this!
same
You're so helpful. I am learning at 11 and you teach so well.
Dont stop
This guy is really good!!!! Wow... It actually makes sense
Thanks for clearnig the concept thank u so much😁😁
from math import sqrt
for i in range(1,501):
if(i%(sqrt(i))==0):
print(i)
for i in range(1,500):
i *= i
if i
Hey Richie, tried your version and it worked just fine. However the 2nd line in your code changes the value of i to (i) square and then when we iterate back to the for statement for next iteration, i is getting reset to the number in range. would like to confirm if this is something that range() offers us that it sets the variable back to its value in the range from the value that it attained during the running of program.
Eg. When i=2, the 2nd line in the code sets the value of i to 4 but when we go back to the for statement after this iteration, i is reset to 3
@@sameer281187 Yes,thats how it suppose to happen. Eg. When i in range is 2 : i *= i is 4 ; i in range is 3 : i *= i is 9 ; i in range is 22 : i *= i is 484 .
Since when the value of i >= 500 in i in range of 23, The if condition won't be calculated and no print is done anymore but still python will calculate for loop from 23 to 500.
Thats why while loop is better for this assignment
n = 1
i = 1
while i = 0:
i = n*n
n += 1
if i
Thank you very much , good bless you always
THAT 'S WAS WONDERFUL IT WAS VERY EASY TO UNDERSTAND THIS CONCEPT
cannot wait for pattern teach us diamond and circle pls a d all shapes also pls teach us merge sort thank u
No
@@msrikavya9651 What no?
Another excellent explanation. Highly encourage people who are studying python at college to definitely add these videos to supplement their learning.
Your video really helped me thank you! I think you explain it well.
well explained sir... Thanks for such amazing videos.
from math import *
n = [ ]
for i in range(1, 501):
n.append(sqrt(i))
for j in n:
if j == int(j):
print("%d"%(j*j))
else:
continue
I saw that most people were doing the for loop from 1 to 500 which seemed a bit redundant to me. I set the for loop to go up to what I aproximated (cause I'm lazy that way) to be the closest number which multiplied by itself would result in a number close to 500, and in order to not go overboard with the results I used the if condition to only display the results less than 500
for i in range(1,25,1):
if i**2 < 500:
print(i**2)
you explained it better than my schoolteacher. THANKYOU
I am really enjoying it 😊the way "Navin" explains
for i in range(1,501):
y=i*i
if y
for i in range(1,100):
j = i * i
if j
Hello sir i like tour way of teaching please upload java tutorial like the way you are teaching python so that it would be easier to understand more quickly
your explanation is very good sir, i have suggest your playlists to my other friends whose are learning websites.
For i in range (1,23)
print (i**2)
Note: Since 23 square is greater than 500 so value of i is restricted to 22
find perfect square not square of number bro
Thx you helped a lot out of all the videos i watched you were the best and made it easy to understand new subscriber thx bro
U made it much easier.... Lots of love from Karnataka
Import math
for i in range(500):
If math.sqrt(i)%1==0:
Print(i)
Import math
For I in range(1, 500):
Print(math.pow(i, 2))
u can not use capital letter & it will print 1,4,9 upto 249001 which is not askesd.
Being a pakistani and urdu speaker the way of your teaching is very easy thanks sir enjoying your tutorial
I like ur videos...ur teaching was excellent...i am njoying ur videos...tqs for ur videos.... n ur expressing with good smile n Hearfully😀😀
import math as m
for i in range(1,50):
a=m.sqrt(i)
if i%a==0:
print(i)
output:
1
4
9
16
25
36
49
After using this code the ouput coming is :- 1
for I in range (1,501):
s=I*I
If I
You are very good explaining! Love you bro
Thanks a lot Sir!
Really helped
Quiz Solution
# Print all the perfect square number between 1 to 500.
from math import sqrt, floor
for i in range(1, 500):
x = sqrt(i)
if x - floor(x) == 0:
print(i)
for i in range(1, 501) :
if(i*i
for i in range(1,501):
j=1
while(j*j
amazing explanation well polished..better than udacity and other
Perfect squares between 1 and 500:
x = range(1, 501)
for i in x:
print(i * i)
finally i knw this for loop thnk u