[Python Programming Basics to Advanced] : List as Function Arguments | Lab 18P-1

preview_player
Показать описание
This Python programming playlist is designed to take beginners with zero programming experience to an expert level. The course covers installation, basic syntax, practical scenarios, and efficient logic building. The course material includes PDF handouts, review questions, and covers a wide range of topics, from data types to advanced functions like Lambda and Recursive functions, Generators, and JSON data parsing.

Continuing our discussion on Lists, we will see how we can use a list as Function Argument (input or output). Nothing special is needed for this because Python supports Duck Typing.
We will do a couple of practice tasks as well.

Complete Playlist:

If you have the basic programming knowledge and interested to learn Object-Oriented Programming in Python, check out this playlist:

Lab Manual 18 can be downloaded from here:

Review Questions:
Given at 13:15

#PythonProgramming #python #pythontutorial
Рекомендации по теме
Комментарии
Автор

Hey! I just found your channel and subscribed, love what you're doing! Particularly, I like how clear and detailed your explanations are as well as the depth of knowledge you have surrounding the topic! Since I run a tech education channel as well, I love to see fellow Content Creators sharing, educating, and inspiring a large global audience. I wish you the best of luck on your YouTube Journey, can't wait to see you succeed!
Your content really stands out and you've obviously put so much thought into your videos! I applaud you for that and really wish you the best for the future!

Cheers, happy holidays, and keep up the great work :)

empowercode
Автор

Review Question:
def dispList(x):
a=""
c=0
b=len(x)
for i in x:
c+=1
if c<b-1:
a+=str(i)+", "
elif c<b:
a+=str(i)+" and "
else:
a+=str(i)
return a
fruits=["Apple", "Banana", "Orange", "Pear", "Mango"]
print(dispList(fruits))

AsadAli-owie
Автор

Ans:
def dispList(x):
a=""
c=0
b=len(x)
for i in x:
c+=1
if c<b-1:
a+=str(i)+", "
elif c<b:
a+=str(i)+" and "
else:
a+=str(i)
return a
fruits=["Apple", "Banana", "Orange", "Pear", "Mango"]
print(dispList(fruits))

hamzaubaid
Автор

def displist(n):
if(len(n)>1):
a=0
while(a<len(n)-2):
print(n[a], end=', ')
a+=1
else:
print(n[len(n)-2], end=' and ')
print(n[len(n)-1])
else:
print (n[0])
n=['apple', 'mango', 'guava']
x=displist(n)

amaanmajid
Автор

def displist(a):
b=""
c=len(a)-2
for i in range(len(a)):
if (i<c):
m=str(a[i])+", "
elif (i==c):
m=str(a[i])+" and "
else:
m=str(a[i])
b+=m
return b
a=["Apple", "Banana", "Orange", "Pear", "Mango"]
print(displist(a))

shahwarsadaqat
Автор

Review Question:
def displist(a):
n=''
u=len(a)-2
for i in range(len(a)):
if (i<u):
m=str(a[i])+', '
elif (i==u):
m=str(a[i])+' and '
else:
m=str(a[i])
n+=m
return n

fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(displist(fruits))

noorulhuda
Автор

Question:"
def displist(a):

b=""

T=len(a)-2

for i in range(len(a)):

if (i<T):

d=str(a[i])+", "

elif (i==T):

d=str(a[i])+" and "

else:

d=str(a[i])

b+=d

return b

a=["Apple", "Banana", "Orange", "Pear", "Mango"]

print(displist(a))

MuhammadQasim-erwb
Автор

def dispList(x):
a=""
c=0
b=len(x)
for i in x:
c+=1
if c<b-1:
a+=str(i)+", "
elif c<b:
a+=str(i)+" and "
else:
a+=str(i)
return a
fruits=["Apple", "Banana", "Orange", "Pear", "Mango"]
print(dispList(fruits))

arslanrafiq
Автор

#Review Question:
def displist(a):
n=''
u=len(a)-2
for i in range(len(a)):
if (i<u):
m=str(a[i])+', '
elif (i==u):
m=str(a[i])+' and '
else:
m=str(a[i])
n+=m
return n

fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(displist(fruits))

asmaabhatti
Автор

##Review Question##
def displist(a):
b=""
c=len(a)-2
for i in range(len(a)):
if (i<c):
d=str(a[i])+", "
elif (i==c):
d=str(a[i])+" and "
else:
d=str(a[i])
b+=d
return b
a=["Apple", "Banana", "Orange", "Pear", "Mango"]
print(displist(a))

dawoodimtiaz
Автор

REVIEW ANSWER:

def displist(a):
n=''
u=len(a)-2
for i in range(len(a)):
if (i<u):
m=str(a[i])+', '
elif (i==u):
m=str(a[i])+' and '
else:
m=str(a[i])
n+=m
return n
fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(displist(fruits))

areebaazhar
Автор

def displist(a):
n=''
u=len(a)-2
for i in range(len(a)):
if (i<u):
m=str(a[i])+', '
elif (i==u):
m=str(a[i])+' and '
else:
m=str(a[i])
n+=m
return n

fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(displist(fruits))

MuhammadTalha-xmul
Автор

#Review_Question
def displist(a):
a.insert(-1, 'and')
s=''
for i in range(len(a)):
if i<(len(a)-3):
s+=str(a[i])+', '
else:
s+=str(a[i])+' '
return s
Fruits=['kiwi', 'mango', 'peach', 'apricot', 'grapes']
print(displist(Fruits)

abdulrehmankhalid
Автор

#ReviewQuestion
def displist(a):
t=''
a.insert(-1, ' and ')
for i in range(len(a)):
if(i<(len(a)-3)):
x=str(a[i])+', '
else:
x=str(a[i])+''
t+=x
return t

## Main Program ##
List=['name', 'class', 'roll number', 'marks']
print(displist(List))

irsaidress
Автор

## Review Question ##
def dispList(x):
y=''
for i in range(len(x)):
if(i<len(x)-2):
z=str(x[i])+', '
else:
if (i==len(x)-2):
z=str(x[i])+' and '
else:
z=str(x[i])
y+=z
return y

## Main Program ##
fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(dispList(fruits))

habibaasif
Автор

Task)
def dispList(x):
l = ''
for i in range(0, len(x)):
if(i==len(x)-2):
q = str(x[i]+' and ')
elif(i<len(x)-2):
q = str(x[i]+', ')
else:
q = str(x[i])
l+=q
return l
x = ['Orange', 'Mango', 'Banana', 'Pomegranate']
print(dispList(x))

hishamawan
Автор

#Rev Question#
def displist(x):
z=''
p=len(x)-2
for i in range(len(x)):
if(i<p):
q=str(x[i])+', '
elif(i==p):
q=str(x[i])+' and '
else:
q=str(x[i])
z+=q
return z


fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(displist(fruits))

talhakamboh
Автор

#Review Question
def displist(x):
y=""
z=len(x)-2
for i in range(len(x)):
if (i<z):
d=str(x[i])+", "
elif (i==z):
d=str(x[i])+" and "
else:
d=str(x[i])
y+=d
return y
x=["Apple", "Banana", "Orange", "Pear", "Mango"]
print(displist(x))

zainulhassan
Автор

def dispList(s):
l=len(s)-2
a=''
for i in range(len(s)):
if(i<l):
b=(s[i]+', ')
elif(i==l):
b=(s[i]+' and ')
else:
b=(s[i])
a+=b
return a

##Main Program
fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(dispList(fruits))

saifullahafzal
Автор

Review:
z=[]
def dispList(x):

for i in range(len(x)):
if(i<len(x)-1):
z.insert(i, str(x[i])+", ")
elif(i==x.index(x[-1])):
z.insert(i, "and"+ x[i]+".")
else:
z.insert(i, str(x[i]))
d=''
for i in z:
d+=str(i)
return d
fruits=['Apple', 'Banana', 'Orange', 'Pear', 'Mango']
print(displist(fruits))

dawood