What is the difference between calling
start() and run() on threading.Thread?Answer:
If you call run() directly, it will execute in the current thread like a normal function β without creating a new thread and without parallelism.
This is the key difference: start() launches a separate execution thread, while run() just runs the code in the same thread.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
PyData Careers
Python Data Science jobs, interview tips, and career insights for aspiring professionals.
π1
Please open Telegram to view this post
VIEW IN TELEGRAM
β€5
What does
nonlocal do and where can it be used?Answer:
This is often used in closures to maintain and update state between calls to the nested function.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
β€2
πΈ PacketSDK--A New Way To Make Revenue From Your Apps
Regardless of whether your app is on desktop, mobile, TV, or Unity platforms, no matter which app monetization tools youβre using, PacketSDK can bring you additional revenue!
β Working Principle: Convert your app's active users into profits π₯βπ΅
β Product Features: Ad-free monetization π«, no user interference
β Additional Revenue: Fully compatible with your existing ad SDKs
β CCPA & GDPR: Based on user consent, no collection of any personal data π
β Easy Integration: Only a few simple steps, taking approximately 30 minutes
Join usοΌhttps://www.packetsdk.com/?utm-source=SyWayQNK
Contact us & Estimated income:
Telegram:@Packet_SDK
Whatsapp:https://wa.me/85256440384
Teams:https://teams.live.com/l/invite/FBA_1zP2ehmA6Jn4AI
β° Join early ,earn early!
Regardless of whether your app is on desktop, mobile, TV, or Unity platforms, no matter which app monetization tools youβre using, PacketSDK can bring you additional revenue!
β Working Principle: Convert your app's active users into profits π₯βπ΅
β Product Features: Ad-free monetization π«, no user interference
β Additional Revenue: Fully compatible with your existing ad SDKs
β CCPA & GDPR: Based on user consent, no collection of any personal data π
β Easy Integration: Only a few simple steps, taking approximately 30 minutes
Join usοΌhttps://www.packetsdk.com/?utm-source=SyWayQNK
Contact us & Estimated income:
Telegram:@Packet_SDK
Whatsapp:https://wa.me/85256440384
Teams:https://teams.live.com/l/invite/FBA_1zP2ehmA6Jn4AI
β° Join early ,earn early!
β€2
π Tricky Python Interview Question
> What will this code output and why?
βQuestion: Why are list1 and list3 the same?
π Explanation:
Default arguments in Python are evaluated once β at function definition, not at each call.
So lst=[] is created once and preserved between calls if you don't explicitly pass your own list.
π§ What happens:
- extend_list(10) β uses the shared list [], now it is [10]
- extend_list(123, []) β creates a new list [123]
- extend_list('a') β again uses the shared list β [10, 'a']
π Result:
β How to fix:
If you want a new list created by default on each call, do this:
This is a classic Python interview trap β mutable default arguments.
It tests if you understand how default values and memory scope work.
https://t.iss.one/DataScienceQβοΈ
> What will this code output and why?
def extend_list(val, lst=[]):
lst.append(val)
return lst
list1 = extend_list(10)
list2 = extend_list(123, [])
list3 = extend_list('a')
print(list1, list2, list3)
βQuestion: Why are list1 and list3 the same?
π Explanation:
Default arguments in Python are evaluated once β at function definition, not at each call.
So lst=[] is created once and preserved between calls if you don't explicitly pass your own list.
π§ What happens:
- extend_list(10) β uses the shared list [], now it is [10]
- extend_list(123, []) β creates a new list [123]
- extend_list('a') β again uses the shared list β [10, 'a']
π Result:
[10, 'a'] [123] [10, 'a']β How to fix:
If you want a new list created by default on each call, do this:
def extend_list(val, lst=None):
if lst is None:
lst = []
lst.append(val)
return lst
This is a classic Python interview trap β mutable default arguments.
It tests if you understand how default values and memory scope work.
https://t.iss.one/DataScienceQ
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
PyData Careers
Python Data Science jobs, interview tips, and career insights for aspiring professionals.
β€2
