Skip to main content

Posts

Top 15 Python Questions and Answers

Q-1. What Is The Function To Randomize The Items Of A List In-Place? Ans.  Python has a built-in module called as <random>. It exports a public method <shuffle(<list>)> which can randomize any input sequence. import random list = [ 2 , 18 , 8 , 4 ] print "Prior Shuffling - 0" , list random . shuffle ( list ) print "After Shuffling - 1" , list random . shuffle ( list ) print "After Shuffling - 2" , list Q-2. What Is The Best Way To Split A String In Python? Ans.  We can use Python <split()> function to break a string into substrings based on the defined separator. It returns the list of all words present in the input string. test = "I am learning Python." print test . split ( " " ) Program Output. Python 2.7 . 10 ( default , Jul 14 2015 , 19 : 46 : 27 ) [ GCC 4.8 . 2 ] on linux [ 'I' , 'am' , 'learning' , 'Python.' ] Q-3. What Is The R...