- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rajendra Dharmkar has Published 453 Articles
Rajendra Dharmkar
3K+ Views
Whenever you want to add or subtract(apply an offset) to a date/time, use a datetime.datetime(), then add or subtract datetime.timedelta() instances. A timedelta object represents a duration, the difference between two dates or times. The timedelta constructor has the following function signature − datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]) ... Read More
Rajendra Dharmkar
13K+ Views
To insert a date in a MySQL database, you need to have a column of Type date or datetime in your table. Once you have that, you'll need to convert your date in a string format before inserting it to your database. To do this, you can use the datetime ... Read More
Rajendra Dharmkar
9K+ Views
We can pass re.IGNORECASE to the flags parameter of search, match, or sub −Example import re print (re.search('bush', 'BuSh', re.IGNORECASE)) print (re.match('bush', 'BuSh', re.IGNORECASE)) print (re.sub('bush', 'xxxx', 'Bushmeat', flags=re.IGNORECASE))Output xxxxmeat
Rajendra Dharmkar
14K+ Views
According to Python docs, re.finditer(pattern, string, flags=0)Return an iterator yielding MatchObject instances over all non-overlapping matches for the RE pattern in string. The string is scanned left-to-right, and matches are returned in the order found. Empty matches are included in the result. The following code shows the use of re.finditer() method ... Read More
Rajendra Dharmkar
11K+ Views
The re.compile() methodre.compile(pattern, repl, string): We can combine a regular expression pattern into pattern objects, which can be used for pattern matching. It also helps to search a pattern again without rewriting it. Example import re pattern=re.compile('TP') result=pattern.findall('TP Tutorialspoint TP') print result result2=pattern.findall('TP is most popular tutorials site of India') ... Read More
Rajendra Dharmkar
4K+ Views
The following code extracts floating numbers from given text/string using Python regex. Example import re s = "Sound Level: -11.7 db or 15.2 or 8 db" result = re.findall(r"[-+]?\d*\.\d+|\d+", s) print result OutputThis gives the output['-11.7', '15.2', '8']
Rajendra Dharmkar
5K+ Views
According to Python documentationPython does not currently have an equivalent to scanf(). Regular expressions are generally more powerful, though also more verbose, than scanf() format strings. The table below offers some more-or-less equivalent mappings between scanf() format tokens and regular expressions.scanf() TokenRegular Expression%c.%5c.{5}%d[-+]?\d+%e, %E, %f, %g[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?%i[-+]?(0[xX][\dA-Fa-f]+|0[0-7]*|\d+)%o[-+]?[0-7]+%s\S+%u\d+%x, %X[-+]?(0[xX])?[\dA-Fa-f]+To extract the filename and ... Read More
Rajendra Dharmkar
3K+ Views
The following code uses a regular expression '(a|b)' to match a or b in the given Python string.We are also using the flag re.I to ignore case of a or b while matching. Example import re s = 'Bank of Baroda' print(re.findall(r'(a|b)', s, re.I))OutputThis gives the output['B', 'a', 'B', ... Read More
Rajendra Dharmkar
5K+ Views
You can subtract a day from a Python date using the timedelta object. You need to create a timedelta object with the amount of time you want to subtract. Then subtract it from the date. Example from datetime import datetime from datetime import timedelta today = datetime.today() yesterday = today ... Read More
Rajendra Dharmkar
3K+ Views
You can use the fromtimestamp() function from the datetime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the datetime object corresponding to the timestamp. Exmaple import datetime timestamp = datetime.datetime.fromtimestamp(1500000000) print(timestamp.strftime('%Y-%m-%d %H:%M:%S'))OutputThis will give the output −2017-07-14 08:10:00Read More
To Continue Learning Please Login
Login with Google