When we develop applications, the problem we often face is a string to datetime conversion. We have to deal with different formats and time zones. Sometimes we need to convert dates and times to human-readable format, and vice versa.Continue reading
You can pass a list as an argument of Python function the same way as any other type and it will be the same type inside the function.Continue reading
If you need to check, whether a particular word is a word in the English dictionary, you can do it in Python.Continue reading
You can create a Python file directly from the terminal. Follow these steps to do it:Continue reading
Subscript and superscript are important when you are dealing with different types of formulas. They are useful in math, chemistry, etc.Continue reading
This lesson is about the Python module called pickle. I’ll tell you what is pickle and how you can use it in Python.Continue reading
To return the day of the week from a string, you have to import the datetime module and run this code:Continue reading
The easiest way to sort letters is to use the join and sorted functions together.Continue reading
There are two methods in Python that can add an element to a list: append and extend. These methods can cause a lot of confusion among beginner Python programmers.Continue reading
If you work with dictionaries, sometimes, you will have to check whether a dictionary is empty.Continue reading
In Python, you can add dictionary keys to a list. This can be achieved with the keys function of a dictionary.Continue reading
To import the current date (year, month, day) and time (hour, minute, second), you have to import the datetime module.Continue reading
Contrary to other programming languages, such as C++ or Java, you don’t specify the data type when defining a variable in Python, but it doesn’t mean that the variable doesn’t have a type.
You can check the variable type using the type function that returns the type of data.Continue reading
If you add a dictionary to a list in Python, it won’t create a copy of this dictionary, but rather add a reference to the dictionary.Continue reading
If you create a variable, you can easily convert it to a string using the print function.
a = 5
sys.maxint is the maximum value for the int variable in Python 2.
Python 3 doesn’t use this property because the int type in Python 3 has no limit. For Python 3, you can use sys.maxsize to check the maximum size lists, strings, dicts, and many other containers can have.Continue reading
If you want to create an empty array (or list because there are no arrays in Python), you can use this line of code:Continue reading
To convert string to time in Python 3 follow these steps:
- Import the time module.
- Assign the result of the time function to a variable.
- Format the value with the strptime function.
- Specify whether you want to display 12 or 24-hour format.