Python Random Tips #9
This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. Do you know the use of ‘else’ in loop (for and while) in Python? The ‘else’ part of statements will get executed only if the for loop completes and reaches it’s end without any ‘break’. #1 Let’s take an example:…
Random Python Question #7
What is ‘Dunder init’? Dunder is ‘Double under(score)’ is one of the special method in Python. As you can see this method got two underscores at beginning and the end of the method name (init). This dunder init is kind of ‘constructor’ from other object oriented programming languages. When a new instance of a Python…
Random Python Question #6
When loc and iloc can give same output? Let’s take an example: what is the output of loc[1] for the above Data Frame? When we use iloc[1], the output is: That is, the output is same for both loc and iloc. Please note: We need to provide label as input for data filtering for loc.…
Random Machine Learning #3
When Feature Scaling should be done? Feature Scaling should be done after splitting the data into train and test datasets. Feature scaling techniques such as normalization will be done using the train data. The important reason for normalization technique to be done after the train and test data split is to avoid data leakage. If…
Random Machine Learning #2
What is Feature Scaling? During the data pre-processing stage, feature scaling is used to scale the independent variables within the same range (say between 0 and 1 or between -1 and +1). Why we need to do the feature scaling? This will ensure no independent variable dominates the machine learning algorithms. Do you know? Feature…
#Random Python Question #5
What is the result when you execute the below Python code: month_list=[‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’] print(month_list[8:]) (1) IndexError (2) [] (3) ‘Mar’ (4) ‘Aug’ What’s the correct result from the above 4 options?
Python Random Tips #8
This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. How do we concatenate multiple lines from a file? #1 Here is one way: Note: If we need we can add one space after each line (if required), otherwise we have just concatenated 3 lines from a file into a…
Python Random Tips #7
This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. In this section, let us see some quick questions & answers with Python code examples: #1 How to remove the last element from a Python list? #2 append() vs entend()? Append() adds the element to the end of the list.…
Random Python Questions #4
0.1 + 0.4 == 0.5 The above is ‘True’, using Python script execution, right? Of course, yes. But if you try in Python script 0.1 + 0.2 == 0.3 this will return ‘False’. It supposed to return ‘True’ but why it gives ‘False’. Why? Do you know some of the above == return ‘False’ instead…
Something went wrong. Please refresh the page and/or try again.