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 PythonContinue reading “Random Python Question #7”

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.Continue reading “Random Python Question #6”

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’ insteadContinue reading “Random Python Questions #4”

Random Python Questions #2

Please look at the below code: Obviously this is a tuple. But the below input is NOT a tuple. This is an integer. Please note that even-though we used the tuple notation ( ), the type is shown as integer and not a tuple. Is there any easy or simple way to change “tuple2” toContinue reading “Random Python Questions #2”

Random Python Questions #1

What is the result of the below Python code: from collections import Counterinput_dictionary = {‘a’:5, ‘b’:3, ‘c’: 1, ‘b’:2}print(Counter(input_dictionary)) Result:Counter({‘a’: 5, ‘b’: 2, ‘c’: 1}) Question: Even-though we have 2 values for the key ‘b’ in “input_dictionary”, the result has only one ‘b’ key/value pair. Do you know why? What’s the reason?

Design a site like this with WordPress.com
Get started