Python Learning
5.92K subscribers
424 photos
1 video
57 files
105 links
Python Coding resources, Cheat Sheets & Quizzes! πŸ§‘β€πŸ’»

Free courses: @bigdataspecialist

@datascience_bds
@github_repositories_bds
@coding_interview_preparation
@tech_news_bds

DMCA: @disclosure_bds

Contact: @mldatascientist
Download Telegram
#PyQuiz

How many values can a return statement rerurn?
Anonymous Quiz
40%
Only one
17%
One tuple max
35%
Any number
8%
One list only
Wait, why did all functions return 2?

The lambdas don’t capture the value of i at each loop iteration, they capture the variable itself. By the time you call the functions, the loop has finished, and i is left at its final value, 2.

This is called late binding and can cause unexpected behavior when creating closures inside loops.

So as a quick tip, Bind the current value at definition time using a default argument(like shown in the second image) Then each lambda remembers its own i value independently.
❀2
πŸ‘1
#PyQuiz

What is the type of type in Python?
Anonymous Quiz
40%
type
21%
class
29%
object
11%
meta
❀1
πŸ‘2
πŸ”₯1
#PyQuiz

What's the output of bool('False')?
Anonymous Quiz
38%
True
40%
False
5%
None
16%
Error
Python Functions You definitely Need to Know
❀3
πŸ‘4❀3
❀1
#PyQuiz

What's the result of len(set("hello"))?
Anonymous Quiz
42%
5
38%
4
3%
3
17%
Error
Difference Between Variable and Object in Python
❀3πŸ‘1
#PyQuiz

Which is faster: list() or [ ]?
Anonymous Quiz
31%
list()
45%
[ ]
5%
Same speed
19%
Depends on list size
Why did x change too?!

Because x and y are just two names pointing to the same list in memory. When you modify one, the change reflects in both.

Use .copy() or slicing [:] if you want a separate list:
y = x.copy()
That way, you’re not changing the original but just making your own version.
❀3πŸ‘2
#PyQuiz

Which of these is NOT a valid Python data type?
Anonymous Quiz
14%
set
13%
dict
59%
array
13%
tuple
Feels off?

It's because all your objects share one variable (without you realizing it)

At first glance, it seems like every object should start fresh, right? But in this case, count is a class variable, which means it’s shared by all instances of the class.

Every time you create a new Counter(), you’re actually incrementing the same shared variable not something unique to each object.

If your goal is to give each object its own value, define it like this instead

class Counter:
    def __init__(self):
        self.count = 1

Now, each instance has its own count, stored on the object itself . no sharing, no surprises.
❀2
#PyQuiz

What does range(5)[-1] return?
Anonymous Quiz
15%
5
44%
4
15%
-1
26%
Error
❀3