To get the last value in an list using python is a very simple ,we can use Negative indexes , it is the index from the end of the List.
arr_even = [2, 4, 6, 8, 10, 12, 14 ,16 ,18]
print(arr_even[-1])
Output 18
Tutorialshore
To get the last value in an list using python is a very simple ,we can use Negative indexes , it is the index from the end of the List.
arr_even = [2, 4, 6, 8, 10, 12, 14 ,16 ,18]
print(arr_even[-1])
Output 18
*args in python is the special syntax used in python to pass n number of argument in a functions.so by using *args we can pass variable-length arguments to a function.
def sum(*argv): total=0; for num in argv: total += num return total print(sum(1, 2, 3, 4, 5)) #output: 15 def sum(*argv): total=0; for num in argv: total += num return total print(sum(1, 2, 3, 4, 5 ,6 ,7,8)) #output: 36
we know that function has rich set of built in functions in python, so the answer is off course their is a functions in python to join a list of strings to a single string .as the name suggest join() is the function in python to join a list of strings to a single string.Let we check the syntax of join().
string.join(list)
where string is the separator string and list is a list of strings
item= [‘ Hello’, ‘good morning ‘]
string = ‘,’.join(item)
print(string)
Fortunately we have split() built-in function in python to split a string in to a list of strings .we can define any separator, anyway default separator is any whitespace. so by default spilt() function split a string in to a list of strings based on any whitespace.
string.split(separator, maxsplit)
separator : It is an optional parameter, if we specify based on the separator value split a string in to a list of strings
maxsplit: It is also optional parameter, it specify how many number of splits to , by default it is all the occurrence.
Hello_string = ” Hello, good morning ”
myitem = Hello_string.split(“, “)
print(myitem)