#26 Python Tutorial for Beginners | Array in Python
Вставка
- Опубліковано 4 лип 2024
- 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 dicussing about for else loop:
-- The for-else loop in Python is a control flow structure that combines the for loop and else
statement. The for loop iterates over a sequence of items, and the else statement is executed
after the loop is completed, provided that the loop was not terminated prematurely by a break statement.
Here's the basic syntax:
for item in sequence:
loop body
else:
else block
-- The sequence can be any iterable object, such as a list, tuple, or string. The loop body is executed
once for each item in the sequence, and the item variable takes on the value of each item in turn.
-- If the loop completes normally, without encountering a break statement, then the else block is executed.
This can be useful for executing cleanup code or performing some final action after the loop is finished.
nums=[12,15,18,21,26]
#get first number divisble by 5 print from list and we want if number is not divisible by 5 then print not found every time
for num in nums:
if num% 5==0:
print(num)
break
else:
print("not found")
#get first number divisble by 5 print from list and we want if number is not divisible by 5 then print not found once
nums=[23,24,27,38,29]
for num in nums:
if num% 5==0:
print(num)
break
else:
print("not found")
Github :- github.com/navinreddy20/Python-
Python for Beginners :- bit.ly/3JOLQhl
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 - Наука та технологія
wtf? Almost everytime when i try to guess new things and searching, always this man is on first page with best tutorials. Thank you man))
One reason being, Google/UA-cam filters content according to your preferences. 😄
Oh i got to know array in Python is new thing!!
this generation kids use bad words fluently without hesitation bruh
~wise kid
India needs more teacher like u....we pay laks of fees to clg and learns nothing .
it is clear!
I see you didn't learn English too
@@pragyanbimali66 can we get English class tutorial from you..
😭🤣
@@shameelsha sure!
It took just 3-4 days for understanding basic syntax of python without holding other works because of your videos. These are to the point videos. Each minute has valid content. Thanks to You Mr. Naveen. Our colleges need teachers like you.
That's right
Bro I truly agree
that's call comment
It took me 3-4 days to understand what he is saying.
Visual information is the best way of learning something
I was "Zero" in any programming, Now all my daily jobs is running with python, Because of Mr Naveen Reddy. Thank you sir, The way you teach is nothing but a solution you provide.
"welcome back aliens" never thought I would enjoy this sentence
But we r humans 🦍🦍🦍
@@stockfish3379 are we?
@@stockfish3379 we are aliens wrt the aliens
Perfect said
@tcfreestyler123x what is that
MAN, you're amazing teacher and I could learn this much python in 3 days and its because of you. I like your slang and also the teaching methods. Even after 2 yrs, yours is awesome one during search of course in youtube. Done well congrats :D
Started following your videos on Python. Your way of explanation is amazing. Our country needs teacher like you :)
To find factor of a given number:
Import math as m
a = int(input("Enter your number: "))
print(m.factorial(a))
that helps thank you :)
@@NikSy 'import' ( lowercase i ) :-)
How did u get this??
bhai galat hh factorial ki value sidha dega yeh printing me
x=int(input("enter any value"))
fact=1
for i in range(1,x):
fact=fact*i
print(fact)
yeh shii solution hhh
Great learning experience. Thanks a lot sir. Atleast a guy like me who didn't had any interest in computers , started watching and practicing Python .
I possess a full Udemy course regarding Python3 and I'm quite good in python after finishing 70% of the course.. But I think it could have been better if I took Python3 knowledge from your lectures...
Kudos to you reddy ji!!!
❤️❤️
U9yt
i wish i had professors or HOD like him engineering would have been heaven
#ArraySorting
from array import array
x = array('I',[0,10,7,2,63,19])
print(sorted(x))
import array
a=array.array('i', [23,22,56,97,-68])
b=sorted(a)
for i in b:
print(i)
It would be better in case you want integers individually
@@dhruvdutt2749 Why arrray.array, array( , ) is sufficient na?
@@harikpriyatirumalaraju674 not in my situation
Dhruv Dutt why?
@@harikpriyatirumalaraju674 because i used import array instead of From array import Array/ From array import *
1)
from array import *
valori = array('i',[2,4,8,7,3,42,109,10000,100908])
while True:
print(sorted(valori))
break
2)
from math import*
x=int(input("Qual è il fattoriale di questo numero?"))
while True:
print(factorial(x))
break
The way you teach is really awesome, not making any confusion, sometimes we really want to have some doubt to ask but you are making it a bit difficult to have doubt☺️☺️
1) from array import *
vals=array('i',[1,50,8,25,91,22])
vals=sorted(vals)
print(vals)
Why we haven't be use sorted like
vals.sorted()
But we use reverse
vals.reverse() like this???
@@priyanshupatel02 same doubt,,,,,I think it is based on somthing like return function,,,,If u got the answer,,then plz let me know too!!
@@crosswalker45 Reverse method parameter ni leta
And sorted takes parameter..
That's why sorted(list) will work...and for working reverse, you need to directly call this with list..without any parameter..like List.reverse()
This sending me one who doing programming
## Sort array using selection sort ###
import array as arr
""" selection sort """
val = arr.array('i',[4, 5,-5,-12, 6, 7, -8])
print("before sort:",val)
for a in range(len(val)-1):
for b in range(a+1,len(val)):
if val[a] > val[b]:
val[a],val[b] = val[b],val[a]
print("
after sort:",val)
from array import *
val = array('i',[21,15,43,-66,100])
print("sorted array = ", sorted(val))
num = 1
x = int(input("Enter the Number:\t"))
for i in range(1, x+1):
num = i * num
print(num)
sir im enjoying the python course
you are doing such A GRAET WORK
answer of 2nd question is
import math
a = int(input("Enter your number: "))
print(math.factorial(a))
bhai galat hh isme direct value print kr dega
x=int(input("enter any value"))
fact=1
for i in range(1,x):
fact=fact*i
print(fact)
The quiz questions at the end are being covered. Can you please mention it in the description
true the sub button must be placed at bottom right
hello sir
a simple request from side.
could you please write assignment questions in description instead of showing them in end of video.
If you do it for making suspense then it is okay but please show them in left bottom side instead of showing them on top because at the end of the video telusko logo comes and questions got invisible.
So please consider this request.
Thank You.. you are doing great!!
I like the style in the end of every video--" ba biie" 🤭🤭😂😂
...
i am glad that i found your channel on top when i searched for python and rest is history.
Thanks😊❤
You are the only teacher who makes me feel that coding is not so difficult as I think.. Thank you sir
Factorial Algorithm created by me without using any prebuild function:
print ( "Enter a Number to find its factorial: " , end="" )
inp = int ( input( ) )
ans = 1
for x in range ( inp ) :
ans = ans * ( x + 1 )
print ( "Factor of" ,inp, "is:" ,ans )
very good
Second answer
number=int(input(type number))
factorial=1
for I in range(1,number+1):
factorial=factorial*i
print(factorial)
Awesome bro
Factorial*I
I think this is the best python short tutorial.worth watching.
Thank you very much.
really found this channel very useful any people dont go deep in beginners python but u taught us from basic to deep so very much thankyou to u sir
I'm learning python almost 1month but I have no much knowledge about array or others.. But when I start watching your tutorial, I have got much knowledge and improve myself.
Thanks sir..
Finally the wait is over 2 days was a long time without you sir😊
We love you sir
Sorting array without using sorted() -
from array import *
arr=array('i',[4,3,1,2,5,23,45,56,12,7,9])
for i in range(len(arr)):
for j in range(len(arr)-i-1) :
if arr[i]>arr[i+j+1] :
arr[i],arr[i+j+1]=arr[i+j+1],arr[i]
print(arr)
Sir your Lectures are really amazing , Thanks a lot for helping us. Mee lanti teachers undadam maaku chaala anandamga undi. Future lo inka chaala videos upload chestarani aasistunnamu.
Thank you very much for your valuable videos on python..it's simply amazing. You made Python very simple and easy to understand. Once again thank you for your effort.
Thank Q sir,We are paying fee in colleges but it does'nt give the practical Knowledge,but your are giving your best.Keep doing videos and inspire many
On the 26th tutorial. starting as a complete Noob! however... your videos may be making me over confident lol. other than your very fast dialect you are one of the greatest teachers i have yet to encounter lol. thank you for posting these videos. Your hard work is very much appreciated.
The best videos i have ever seen... U discussed every basic , which is extremely extremely extremely beneficial 😍😍... I m a beginner and also faced a lot of difficulties.. but after seeing ur vdos , now i m clear about python.. my next mission is Django... And i will follow ur videos so that I don't face any kind of difficulties...thank you sooooooooooooooo muchh🥰🥰🥰🥰🥰🥰
Such a great lesson, genuinely considering learning hindi just to honor one of the best teachers I've ever had!
from array import *
yes = array('i',[33,44,22,11])
print(sorted(yes))
in qustion, it is asked for alphabet arrangement
am telling you you've done a good job... i went in the bush.... lol
thnx man it helped me
bro where you get aaray in pycham aaray is working
Lol write the code in loop not pre defined functions 💩💩💩💩🤦♂️💩💩
from array import *
values = array("i", [7,4,9,2,6,2,1])
x=len(values)
for i in range(x):
for j in range(i+1, x):
if values[i]>values[j]:
temp = values[i]
values[i]=values[j]
values[j]=temp
print(values)
for swap u csn use a[i],a[j]=a[j],a[i]
Here you use selection sort algorithm am I correct?
I love your way of explaining,as you first do it wrong,then tell us the write method.
Thank You 😀😀
I've warched and searched so many videos on internet but found no one conceptual however Reddy's lectures are conceptual and has practical approch.
Stay blessed reddy bro
You are a very good teacher. Love your Python tutorials! Thank you!!
#1-sorting
from array import *
arr=array('i',[11,7,9,6,-4,3,5])
for i in range(len(arr)):
for j in range(i+1,len(arr)):
if(arr[i]>arr[j]):
arr[i],arr[j]=arr[j],arr[i]
print(arr)
#2-factorial
number=int(input("Enter a number:"))
value=1
for i in range(1,number+1):
value=value*i
print(f"factoiral of {number} is",value)
instead of using value = value * i you can use value *= i to make it simpler
Thank you. It is more easy than I expected by your way of teaching.
What a fantastic content sir! You are a great help to us...loving the python series. Thank you for your indeed efforts.
from array import *
a=array('i' , [2,6,5,0,1])
b=array('i',[])
for y in range(max(a)+1):
if y in a:
b.append(y)
else:
pass
print(b)
it cannot order the negative numbers i-e(-6)
n=int(input("Enter the number whose factorial you want to know: "))
m=1
for i in range(1,n+1):
m=m*i
print(m)
Why n+1 ??
@@soumsgaming238 because it will go from 1 to n.. definition of range
@@hritwikhaldar9272 Accha thank you I am learning python
Hritwik Haldar Hey a try fixing your code bit ! It doesn’t work if I give 0 😁😉
Been watching your videos all day sir
Feel like i have pretty decent grab of python
Thanks sir!
I should thank you for Python Videos, I have spent lot of money for coaching center and learnt nothing. this is the best tutorial till now I found. many thanks to you.
program 1
from array import*
vals= array('i',[2,5,1,3,6,4,9,8,7])
print(sorted(vals))
program 2
from math import*
x= int(input('enter a no'))
print(factorial(x))
Print(math.factorial(x))
no=int(input("Enter any number: "))
fact=1
for n in range(no,1,-1):
fact=fact*n
print("The factorial of ",no," is: ",fact)
In range u have to give 0 in 2nd place
Not 1 😔
She saved time by eliminating multiplication with 1.
Thank a lot sir for such amazing teaching......we need teachers like u .....
Telusko is the Best Channel on the Earth to Learn Programming! Hats Off... Dear Navin!
sorting an array without using inbuilt function
from array import *
arr = array('i',[6,23,44,21])
for i in range(4):
for j in range(i+1):
if arr[j]>arr[i]:
arr[j],arr[i] = arr[i],arr[j]
for x in range(4):
print(arr[x])
Great work
Please make videos on the python projects
It will be very helpful to us
you have the gift of teaching things very easily
I like your video. Easy to understand. Learn new things as well as reinforce things I already know in a short time.
#sorted arrays
from array import *
vals = array("i" ,[5,9,11,16,3,10,2,1,6])
values = array(vals.typecode , (i for i in vals))
values = sorted(values)
for i in values:
print(i)
#factorial
from math import *
x = int(input("Enter the number:"))
for i in range(x):
x = factorial(x)
print(x)
break
Solution for no 1
from array import array as a
nums = a("i",[99,85,57,91,100])
l = list(a for a in nums)
l.sort()
nums = a("i",(a for a in l))
print(nums)
You may also use nums only in place of a for a in nums, just to improve efficiency
He taught the for loop in arrays. What a LEGEND!
Love on python increases day by day with ur tutorials!!
"Sorted Numbers in ascending order"
from array import *
nums = array('i',[4, 3, 5, 6, 1])
for i in range(len(nums)):
for j in range(len(nums)-1):
if nums[j] > nums[j + 1]:
temp = nums[j + 1]
nums[j + 1] = nums[j]
nums[j] = temp
print(nums)
Hai I cant understand will be please help me by explaining that
Directly use *list.sort()* function
print("LIST SORTER:-
")
n=int(input("enter the number of elements to be inserted and sorted: "))
def sort(a):
for passnumber in range(len(a)-1,0,-1):
for i in range(passnumber):
if a[i]>a[i+1]:
m=a[i]
a[i]=a[i+1]
a[i+1]=m
a=[]
for i in range(0,n):
x=int(input("enter element: "))
a.append(x)
sort(a)
print(a)
Or use this
2.
n = int(input('Enter the number '))
count = 1
for i in range(1, n+1):
count = count * i
print(count)
wrong answer my friend
Hey sir! Excellent video; explanation is very clear and easy to follow. I just have one piece of feedback: I was wondering if you could edit the closed captions for this video? I have noticed some instances where the auto-generated captions display the wrong words (for example, around the 2.5-minute mark, import Eddie as so instead of import array as arr) and this might make it more difficult for the folks globally who rely on closed captions to understand the videos. Thank you very much and have a great day!
thank you soo much Naveen Reddy sir for providing such a valuable vedios....thank u you tub
#solution 1st problem
from array import *
val=array('i',[2,10,3,4,6])
val=sorted(val, key=int)
print(val)
hey hi your code is working fine even without the ("key = int"). May I know y u place the key keyword.
Wats the use of key ?
Print(sorted(var)) will do
assigning old array to new:
vals=array('i',[1,2,3,4])
newarray=vals
this above statement also works then why we are doing this:-
newarray=array(vals.typecode,(a for a in vals))
What happens in a for a in vals? I didnt get that
@@kalyan762 Here, "for a in vals" is similar to for loop, where "a" is a variable,used to traverse the vals. It picks values of array one by one and do the operation, since here only a(before for) is present it copies the array as it is.
The only benefit of using this concept is that,we can do certain operations with all the values of vals and stores it in a new array but this is not possible with the syntax ->(newarray=vals)
Ex-> newarray=array(vals.typecode,(3*a for a in vals)) ,multiplies every element of array with 3 and stores it in new array.
Hope this will help you :)
@@sameernayak9611 thanks a lot for such clear explanation
Thank you so much for this, your lesson has been most helpful.
Superb. I have never seen so attractive way of learning. Thanks alot :-) :-)
num=8
fact=1
if fact
shouldn't it be num instead of fact in if else statement
Keepe Print(fact) with for loop
Otherwise it will print all the values
n=int(input("no.?"))
i=1
out=1
while i
nice ,different solution
Fk it's working
Thank you very much for your videos...I have taken on so much useful information!!
excellent explanation sir especially while saying about coping array values into a new array
Sir whole day we eagerly wait for your quality, elaborately discussed videos but recently someday you don't upload even a single video.. Please sir at least upload two your quality videos daily 🙏🙏..
Instead of replying, our tutor gave you a 'Heart Like', I wonder 'Like' is the acceptance of your request or what....
Donate; lol. You're at the mercy of an electronic guru/sensei
#Factorial
num=int(input("Enter number: "))
fact=1
while(num>0):
fact*=num
num-=1
print("factorial is: ",fact)
why my program is not working
x=int(input('enter a no'))
num=1
while x>num:
x=x*num
num=num+1
print(x)
lol,my num is 1, how can i make it num-1, it will go to zero then negative
actually i think my logic is wrong,ad on decrementing x also,nothing will happen....
u check on ur complier u'll know.
Btw, do u know from where to learn ML
@@neelesh621 nope i don't know
Great as always sir, I really enjoy watching your videos!
love from NEPAL sir > YOur explantion is just wow...... I totally understand about basic of python becz of u sir thank you.
Answer 2:
from array import *
val = int(input("number"))
result = 1
for x in range(1,val+1):
result*=x
print(result)
2)
a=int(input("Enter any number:"))
for i in range(1,a):
a=a*i
print(a)
Great! But it does not work for a=0 (i.e. 0! = 1)
Solution (considering only positive or null values of a):
a = int(input("Enter any number: "))
f = 1
for i in range(1,a+1):
f *= i
print(f)
Sir your way of teaching is excellent
Keep it up sir
Plz upload programming videos in python
I'm new to Python
I am learning a lot from you
thank you my guru :D
2nd
import math
x=int(input(" enter the value"))
var=math.factorial(x)
print(var)
Hehe, nice work lazy dude!
how can i repeat this script?
after getting the result it should ask for another number to enter
I have a doubt:-
In lists we done like
Nums.sort()
But in array it is not working?
i love ur explaining skills sir keep posting more and more
Fantastic explanation of array. And thanks for giving data type signs.😁
from array import *
arr=array('i',[3,8,5,9,3,6])
arr1=sorted(arr)
print(arr1)
For descending order?
@@Rajkumar-vc2pg just type above print(arr1)
arr1.reverse() then you will get decending order
@@raghavchakravorthy3896 yea I'm liking that.. But i don't think it is efficient way to do
factorial???
Sort not working in array
Its very confusing....array array....yeh array array kya hai yeh array array
Sir in your teaching techniques is very technical and just realised you to something me it's good for understanding thanks and bye baii
Print("No.1 coding teacher in India. Salute to this man")
"""lets try and sort an array in ascending order"""
from array import *
vals=array('i',[9,2,8,6,7])
print(vals)
for i in range(5):
for j in range(i+1,5):
if vals[i]>=vals[j]:
vals[i],vals[j]=vals[j],vals[i]
print(vals)
It works but it's not efficient..
@@leepierrelephiri7944 any suggestions..wat can be done? pls help
@@gauravmalhotra007No limits in programming. There are multiple ways of doing it since people take different approach, the most preferred method is the simple one to save memory.
.
>>>vals.sort(reverse = True)
@@leepierrelephiri7944 thank u
@@gauravmalhotra007 '''vals[i],vals[j]=vals[j],vals[i]''' can you plz help explain me this line!!!!
Instead of writing newArr = array(vals.typecode, (a for a in vals)).
cant we directly write newArr = vals
Cool
We can but if we want more requirement in further, we has to initiate the typecode and requirement. It is better to know the depth subject right :)
newArr = vals doesn't create a new array, it assings the 'vals' array to the 'newArr' tag. Thus, each change on the 'vals' array will affect the 'newArr' array, as these are the same arrays. But, it seems that works fine:
newArr = array(vals.typecode, vals)
Best tutor on UA-cam for Python!
Welcome back sir...
Was waiting for you eagerly..
2..........
import math
x=int(input('enter the value '))
for i in range(2,x+1):
if x%i==0:
print('factorial of number is',i)
code isn't working brother!
from array import *
vals = array('d',[4,3,1,12])
vals=sorted(vals)
print(vals)
Everytime you ask , hope you are enjoying the series? Dude, we are in love with this series!
Ur the only person I'm feeling easy to learn from basics.. Plz do make a joins concept in mongodb.. No one has done easily plz
Solution of 1st problem
From array import *
S = array('i',[9,2,40,91,51,2])
For i in sorted (s):
Print (i)
Solution for 2.
No=5
Fact=1
For i in range(1,no+1):
Fact=fact*I
Print (fact)
print("Factorial finding machine")
user= int(input("Please enter you number"))
a=1
b=1
for i in range(1,user+1):
if i
Sir u are awesome literally I am totally impressed by the way u teach