Forwarded from Information for IT Students
#PythonTip
—————-
Use _ in #python console to retrieve the result of the last statement
>>> 3 + 4
7
>>> _ * 3
21
—————-
Use _ in #python console to retrieve the result of the last statement
>>> 3 + 4
7
>>> _ * 3
21
Forwarded from Information for IT Students
#PythonTip
Fraction Calculation
——————————
>>> from fractions import Fraction
>>> a = Fraction(1,3)
>>> b = Fraction(5,4)
>>> print(a+b)
19/12
Fraction Calculation
——————————
>>> from fractions import Fraction
>>> a = Fraction(1,3)
>>> b = Fraction(5,4)
>>> print(a+b)
19/12
Growth of #Python language...
Though it is a very old language, started to attract during 1999 Y2K Computer Issue.
Though it is a very old language, started to attract during 1999 Y2K Computer Issue.
#python3 regex gotcha: not every digit ("\d") looks like digits you know
>>> import re
>>> re.match(r'\d+', '٢٣٤٥٦٧٨٩')
<re.Match object; span=(0, 8), match='٢٣٤٥٦٧٨٩'>
Explanation and solution:
>>> import re
>>> re.match(r'\d+', '٢٣٤٥٦٧٨٩')
<re.Match object; span=(0, 8), match='٢٣٤٥٦٧٨٩'>
Explanation and solution:
Here we use "yield from" to create a simple #Python generator:
🐍📺 Python Generators 101 (Overview) [Video] #python
https://realpython.com/lessons/python-generators-overview/
https://realpython.com/lessons/python-generators-overview/
Realpython
Python Generators 101 (Overview) – Real Python
Hello, and welcome to this course on generators and the yield keyword in Python. Before I show you any code, I’d like to give you a general intuition of what generators are and why you would want to use them. So, first, consider a staircase. You…
As a rule of thumb, do NOT modify a collection / array / list while iterating over it.
For example, this code will NOT print all elements in the list before deleting them. #python #PythonTip
For example, this code will NOT print all elements in the list before deleting them. #python #PythonTip
Using #Python pprint to pretty print a nested data structure:
Did you know that #Python allows you to write tests in your docstrings?
Download and extract a zipfile in #Python in just 2 lines of code
In #Python you can use a classmethod to add alternative constructors to your class: