Python_Labs🐍
587 subscribers
267 photos
11 videos
28 files
204 links
Download Telegram
"is" vs "=="
#pytrick
functools — Higher-order functions and operations on callable objects

partial gives default values to the parameters of a function that would otherwise not have default values.
#pytrick
Functions are first-class citizens in Python
#pytrick
Dicts can be used to emulate switch/case statements

#pytrick
Python's list comprehensions are awesome

even_squares = [x * x for x in range(10) if not x % 2]

#pytrick
Python 3.5+ type annotations
#pytrick
روشی که برای تولید تمام حالت ها در brute-force پسوردها هم استفاده میشود!

itertools.permutations() generates permutations for an iterable.

#pytrick
Peeking Behind The Bytecode Curtain

#pytrick #bytecode
Lambda Functions

(lambda x, y: x + y)(5, 3)

#pytrick
@classmethod vs @staticmethod vs "plain" methods (part 2)

#pytrick
Accessing class and function names at runtime
#pytrick
#pytrick

پایتون 3 اجازه میدهد نام متغیرهای شما unicode باشند. اما باید حتما کاراکترهای مثل حروف باشند...
#pytrick
استفاده از contextlib برای نادیده گرفته شدن exception ها در کد!

import contextlib

with contextlib.suppress(FileNotFoundError):
os.remove('somefile.tmp')


#contextlib
#exception
#pytrick
Multiple sets of kwargs in Python 3.5+

منبع
Forwarded from Python_Labs🐍 (Alireza Akhavan)
functools — Higher-order functions and operations on callable objects

partial gives default values to the parameters of a function that would otherwise not have default values.
#pytrick
#pytrick
پیدا کردن آیتمی با بیشترین تکرار در لیست.

Find The Most Frequent Value In A List.

مطلب مشابه: https://t.me/PyLab/275

منبع
#pytrick
Chained Comparison
منبع
#pytrick

فراخوانی توابع مختلف، اما با آرگومانهای یکسان بر اساس شرط
Chained function call
منبع
#pytrick
For Else

عبارت elseی که برای for است!
این else زمانی اجرا می شود که حلقه ی for به دلیل رسیدن به break خارج نشده باشد (بدون break و عادی از حلقه خارج شده باشد.)
منبع