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,710
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,119
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
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
279
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,284
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
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
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: 3 Solution: The // symbol stands for "floor division". How is that different from the usual / division? / gives you an exact division as a float. // gives the quotient rounded down. Eg. 10 / 3 would be 3.333 10 // 3 is that rounded down to the lower int, ie, 3.
1
6
305
Coding Computing Coach retweeted
Python Quiz: Comment your answer below 👇
26
7
2
76
9,136
Coding Computing Coach retweeted
Replying to @RealBenjizo
Answer: break Solution: When python encounters the break keyword, it exits the currently running loop. The break statement works for both while and for loops.
1
1
128
Coding Computing Coach retweeted
You want to exit a for loop; which statement do you use?
2%continue
81%break
2%yield
15%return
106 votes • Final results
2
1
8
1,374
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: 0 2 4 (on separate lines) Solution: The for-loop lets you run the same code multiple times with different values. Let's start by understanding range(3) this produces a sequence of numbers: 0, 1, and 2. In each iteration of the for-loop, +
1
1
2
339
Coding Computing Coach retweeted
Only 1% of coders get this right on the first try! What's your answer?
50
16
4
149
35,145
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: B Solution: x and y are sets. What does the `-` do on sets? It computes the "set difference". The diagram makes it clear (credit in description): The shaded region is the part of A which is not in B. That is the set difference. +
1
1
5
257
Coding Computing Coach retweeted
Python Quiz: Comment your answer 💯
21
4
1
86
9,350
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: A Solution: a and b are sets. The code computes a ^ b What is this operator ^? The operator's action is called Symmetric Difference. The diagram shows it the symmetric difference of A and B as shaded: +
1
1
4
175
Coding Computing Coach retweeted
Python Quiz: What is the Output?
16
2
1
73
7,591
Coding Computing Coach retweeted
Replying to @PythonPr
Answer: A. HelloWorld Solution: "Hello" + "World" Here is an addition of two strings. As we know, strings are sequences of characters. How do you add two of these? The answer is that the + operator does different things for different types. Numbers get summed up. But, +
1
1
3
340
Coding Computing Coach retweeted
Python Quiz: Comment your answer 💯
50
6
2
100
11,931