# Python Coding Interview Questions

> > > > > > Python Coding Interview Questions

##### Print all the Prime numbers less than 20
i = 2
while(i < 20):
j = 2
while(j i/j) :
print (i," is a prime number")
i = i + 1
##### How does a mutable list works?
list_example = ['Amit','Sumit','Rahul']
print(list_example)
list_example[1] = 'Kamal'
print(list_example)
['Amit', 'Sumit', 'Rahul']
['Amit', 'Kamal', 'Rahul']
##### How to pass a list to a function?
def game_name(name):
for x in game_name
print(x)
example = [‘Cricket’,’Football’,’TT’]
game_name(example)
##### When you don’t know how many arguments will be passed to a function, then you need to pass a variable number of arguments. Show by an example.
def pizza(size, *toppings):
print("\nMaking a " + size + " pizza.")
print("Toppings:")
for topping in toppings:
print("- " + topping)
# Make three pizzas with different toppings.
make_pizza('small', 'pepperoni')
make_pizza('large', 'bacon bits', 'pineapple')
make_pizza('medium', 'mushrooms', 'peppers', 'onions', 'extra cheese')
##### How to split a dataset into train and test in python?
Splitting a dataset into a train and test is one of the initial stages of most of the machine learning models. Following is how you can split the dataset in python:-
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(dataframe_name,target_variable,test_size=0.3, random_state=42)
dataframe_name = the complete dataset as a panda dataframe target_variable = the name of the target variable test_size = 0.3 denotes 70-30 split of the dataset in train and test random_state = 42, Look for the explanation in the next question