Joined May 2019
337 Photos and videos
Pinned Tweet
🚨 Python Testing Series 🚨 Employ testing to gamify your coding. Learn how to test code using pytest. Build a Cash Dispenser project in Test Driven style. Ongoing series of posts, see README at: github.com/CodingComputing/g…
1
20
5,393
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: 125 Solution: a looks like a number, but it's not! The quotes around it make it a string - a sequence of characters. But, int(a) converts it from string to an integer, so b is now the int 123. You can do arithmetic operations on it. Printing b 2 prints 123 2, ie, 125.
1
4
378
Coding Computing Coach retweeted
Replying to @RealBenjizo
Answer: B Solution: The function is the tricky part, let's zoom in on that. The function call passes the argument d to modify_dict. But modify_dict doesn't "modify" d. Rather, it gives the name d to something else (dictionary with grandma). And, that changed d is just a
1
1
1
142
Coding Computing Coach retweeted
Python Question What is the output of this code and why?
7
7
24
3,777
Coding Computing Coach retweeted
Replying to @RealBenjizo
Answer: a. Error Solution: x is a tuple. Tuples are immutable, ie, you cannot change it after it is created. In the function call to func, the argument is the tuple. However, func tries to modify the index 0 value of this tuple. This gives error because tuples are immutable.
1
1
116
Coding Computing Coach retweeted
Python Question: Let's see who can explan this better. What is the output of this code?
12
5
21
2,019
Indexing starts from 0 for the leftmost item. The more you increase, the rightwards you go. BUT there is a negative indexing feature. The negative index starts from -1 from the rightmost item. The more you decrease, the leftwards you go.
181
Tuples are the immutable cousins of lists.
1
149
In python, * doesn't just multiply...
Replying to @PythonDvz
Answer: C a is a str & b is an int. It seems impossible to multiply them using the * operator. But the * operator does different things for different operand types. For str and int, the * operator repeats the str, int times. '5' * 3 repeats the string thrice, ie, "555"
235
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: 52 x is 5, y is 10. In x*y 2, the multiplication happens first (PEMDAS rule) 5*10 2 simplifies to 50 2 that is 52, which gets printed.
1
3
471
Coding Computing Coach retweeted
Python Quiz: What is The Output ?
25
8
86
15,221
Coding Computing Coach retweeted
Replying to @clcoding
Answer: 5 Solution: x is a list [1, 2, 3]. Now we run print(x.pop(1) x[1]) The expression inside print now evaluates as x.pop(1) this actually removes the item at index 1 in x (thus modifying x), AND returns it here. Thus x.pop(1) evaluates to 2, and modifies x to [1, 3]
1
1
5
495
Coding Computing Coach retweeted
What will be the output of the following Python code? x = [1,2,3] print(x.pop(1) x[1])
48% 5
9% 6
28% Error
14% None
232 votes • Final results
6
2
36
12,839
Coding Computing Coach retweeted
Replying to @RealBenjizo
Answer: a. tuple Solution: In Python, a comma makes a tuple. The parentheses are actually the optional part. So, what many people assume is "python magic" like a, b = b, a is actually just a tuple assignment. The comma between the list [1, 2] and the tuple (1,2) makes a tuple
1
1
114
Coding Computing Coach retweeted
Replying to @RealBenjizo
return = "I am done. Clean up, take this value and go back." yield = "I am done for the moment, I can take back a value. But instead of cleaning everything up, let me save my work to take it from that point when I come back to work on the next value."
1
1
6
247
Coding Computing Coach retweeted
Pythonistas, where are you? Explain the difference between return and yield in Python functions as if I am 10.
5
1
17
5,067
Coding Computing Coach retweeted
I got it wrong, too. It turns out that boolean "not" has a lower precedence than comparison operators, so this expression gets evaluated as not (None != False) => not True => False
2
1
2
169
Coding Computing Coach retweeted
Replying to @RealBenjizo
Answer: True Solution: Python considers None as a "falsy" value. So, its conversion to bool is False. Now, `not` reverses the bool value of its operand. Hence, not None produces the opposite of None's bool value, giving True. So it simplifies to True != False that's True.
1
1
3
476
Coding Computing Coach retweeted
Python Question: What is the output of this code and why?
14
4
25
4,808
If a programming language allows something, doesn't automatically mean it's a good idea to do!
1
241
For anyone who needs to know... Kolourpaint does on Linux what Paint does on Windows
2
250