Resultados de búsqueda: "#Python_tip"

12 resultados
Daily Python Tip 🐍🐧
Daily Python Tip 🐍🐧@python_tip·
you can split a string on all non-word characters with re.split: >>> import re >>> re.split(r'\W', 'hello world, 2020-04-06, 333/blabla') ['hello', 'world', '', '2020', '04', '06', '', '333', 'blabla'] #python #python_tip
English
0
14
55
0
Daily Python Tip 🐍🐧
Daily Python Tip 🐍🐧@python_tip·
#python_tip from @NurmeAve: Python's divmod() is one way to convert months into years and months: divmod(1, 12) # (0, 1) -> 0 years & 1 month divmod(12, 12) # (1, 0) -> 1 year & 0 months divmod(55, 12) # (4, 7) -> 4 years & 7 months
English
1
10
46
0
Daily Python Tip 🐍🐧
Daily Python Tip 🐍🐧@python_tip·
#python_tip by @raymondh: several ways to interactively display results of a calculation: # Two liner >>> q = 3.5 * 1.5 >>> q 5.25 # Second expression >>> q = 3.5 * 1.5; q 5.25 # Walrus >>> (q := 3.5 * 1.5) 5.25 # Invisible >>> q = 3.5 * 1.5
English
2
19
60
0
Daily Python Tip 🐍🐧
Daily Python Tip 🐍🐧@python_tip·
None is evaluated as False so you can write >>> results = None >>> print(results or "No results") Use case: def query(q, connection=None): conn = connection or create_connection() c = conn.cursor() ... #python_tip by @IDryer and @Pythonic_
English
0
11
35
0
د. أحمد طيب
د. أحمد طيب@ahmad_tayeb·
عدة خيارات جميلة وسريعة لتنسيق شكل المخرج في البايثون: print(x, "/", y, "=", x / y) print(f"{x} / {y} = {x / y}") print("{} / {} = {}".format(x, y, x / y)) print("{n1} / {n2} = {r}".format(n1= x, n2 = y, r= x / y)) print("%d / %d = %.2f" % (x, y, x / y)) #python_tip #cpit110
د. أحمد طيب tweet media
0
2
4
0
Daily Python Tip 🐍🐧
Daily Python Tip 🐍🐧@python_tip·
Use charset_normalizer to detect around 90 encoding and 50 languages. >>> from charset_normalizer import detect >>> my_byte_str = '我没有埋怨,磋砣的只是一些时间。'.encode('gb18030') >>> detect(my_byte_str).get('encoding') 'gb18030' #python_tip by @Ousret
English
0
6
43
0