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
Python interview questions for beginners
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
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)
We have remove in os to delete a file in Python
os.remove(file_name)
import os os.remove("employee.csv") print("employee.csv deleted using command to delete a file in Python")