Coding Computing Coach (@CodingComputing) header
Coding Computing Coach (@CodingComputing) profile picture

Making Python simple for you, by exploring the fundamentals. Tips and explanations to become code-literate in this AI age. Building @PythonResources

Maximize your coding skills 👇
Joined May 2019
Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)Photo by Coding Computing Coach (@CodingComputing)
🚨 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
21
5,713
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: 0 2 4 (on separate lines) Solution: In this for-loop, the iteration happens over range(3) which is simply a sequence from 0 to 3 (excluding 3) ie, 0, 1, and 2. So, i gets the values 0, 1, and 2 in the 3 iterations. In each iteration, (i*2) gets printed When i=0, +
1
1
2
161
Coding Computing Coach retweeted
Python Quiz: What is the Output?
28
11
1
120
12,132
0 is printed. When i=1, 1*2=2 gets printed. When i=2, 2*2=4 gets printed. So, in the 3 iterations, the output is: 0 2 4 And the loop ends with that, so that is the output.
48
Replying to @PythonPr
Answer: 0 2 4 (on separate lines) Solution: In this for-loop, the iteration happens over range(3) which is simply a sequence from 0 to 3 (excluding 3) ie, 0, 1, and 2. So, i gets the values 0, 1, and 2 in the 3 iterations. In each iteration, (i*2) gets printed When i=0, +
1
1
2
161
Coding Computing Coach retweeted
Replying to @clcoding
Answer: ** is python exponentiation operator. Mathematically, this is simply the "power" or "raised to".' 2 ** -1 is 2 raised to the power (-1), ie, 1/2 which is 0.5
1
1
118
Replying to @clcoding
Answer: ** is python exponentiation operator. Mathematically, this is simply the "power" or "raised to".' 2 ** -1 is 2 raised to the power (-1), ie, 1/2 which is 0.5
1
1
118
Comparing numbers and strings
Replying to @clcoding
Answer: False Solution: Let us compare the values on the sides of ==. The right hand side is 77. The left hand side is x*2, and x is "7", a string. "7"*2 repeats the string "7" 2 times, giving "77". But note that this isn't the number 77, it is a string. That means, +
2
281
Coding Computing Coach retweeted
What will be the output of the following Python code? x = "7" print(x * 2 == 77)
27%True
42%False
7%77
24%Error
1,240 votes • Final results
16
10
1
60
21,289
"77" is a sequence of two characters, '7' and '7' So, "77" is not the same as the number 77. "77" == 77 works out False. So, False is what gets printed.
80
Replying to @clcoding
Answer: False Solution: Let us compare the values on the sides of ==. The right hand side is 77. The left hand side is x*2, and x is "7", a string. "7"*2 repeats the string "7" 2 times, giving "77". But note that this isn't the number 77, it is a string. That means, +
1
1
3
587
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: [5, 5, 5] Solution: The value of x is [5]. Observe that it is a list with a single item, 5. Now, what is x * 3? How do you multiply a list with a number? The answer is, python repeats the list. So, [5] * 3 is the items in the list [5], repeated 3 times. +
1
1
3
378
So, the single item 5 is repeated 3 times. [5] * 3 gives [5, 5, 5]. That is what gets printed.
56
Replying to @PythonPr
Answer: [5, 5, 5] Solution: The value of x is [5]. Observe that it is a list with a single item, 5. Now, what is x * 3? How do you multiply a list with a number? The answer is, python repeats the list. So, [5] * 3 is the items in the list [5], repeated 3 times. +
1
1
3
378
Replying to @PythonPr
Answer: 11 Solution: a is 5 and b is 2. We have to evaluate a + b * 3 ie 5 + 2 * 3 multiplication has higher precedence, so 2 * 3 is worked out first 5 + 2 * 3 simplifies to 5 + 6 which is just 11
2
184
Replying to @PythonPr
Answer: [3, 5, 8] Solution: `sorted` is a built-in function. it takes a list as an argument, and returns a sorted copy of it. The sorting is in increasing order. Therefore, sorted([8, 3, 5]) gives [3, 5, 8].
1
109
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: True Solution: {1, 2} and {2, 1} are sets. In sets, the order of the elements doesn't matter. A set is like a bag with fruits, shuffled. There is no "first" or "second". The only meaningful question is, "Is this item in the bag or not?" {1, 2} has two items: 1, 2 +
1
1
3
441
Coding Computing Coach retweeted
Python Quiz: What is the Output? print({1, 2} == {2, 1})
45%True
38%False
12%Error
5%None
624 votes • Final results
9
6
39
11,670
{2, 1} has exactly the same items as {1, 2}. They are specified with a different order, but a set doesn't preserve the order of items anyway. Two sets are considered equal if they contain exactly the same items. So, {1, 2} == {2, 1} gives True.
60
Replying to @PythonPr
Answer: True Solution: {1, 2} and {2, 1} are sets. In sets, the order of the elements doesn't matter. A set is like a bag with fruits, shuffled. There is no "first" or "second". The only meaningful question is, "Is this item in the bag or not?" {1, 2} has two items: 1, 2 +
1
1
3
441
Replying to @PythonPr
Answer: 77 Solution: x is a string, consisting of one character, 7. What does it mean to multiply a string by a number, like x*2? In Python, it means repetition of the string. x*2 repeats the string "7" twice, resulting in the string "77", which is printed as 77
228