
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
- Tweets13.6K
- Following104
- Followers8.9K
- Likes8.9K
🚨 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…
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,
+
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,
+
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
What will be the output of the following Python code?
print(2**-1)
11%0
63%0.5
21%-2
5%-1
708 votes • Final resultsComparing 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
317
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 resultsWhat 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 resultsAnswer: 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,
+
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.
+
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.
+
Python Quiz: What is the Output?
a = 5
b = 2
c = a + b * 3
print (c)
76%11
3%15
14%21
7%17
422 votes • Final resultsPython Quiz: What is the Output?
x = [8, 3, 5]
print(sorted(x))
82%[3, 5, 8]
8%[8, 3, 5]
3%[5, 3, 8]
7%[3, 8, 5]
441 votes • Final results 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
+
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 resultsPython Quiz: What is the Output?
print({1, 2} == {2, 1})
45%True
38%False
12%Error
5%None
624 votes • Final resultsAnswer: 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
+
Python Quiz: What is the Output?
x = " 7 "
print ( x*2 )
36%14
13%49
46%77
5%72
1,152 votes • Final results



