The replace() function searches for a specified pattern in a string and replaces it with another specified string.
Continue readingAuthor Archives: Tomasz Decker
Convert String to Hex in Python
The hex() function can be used to convert a string to a hexadecimal value. Before using the function the value has to be converted to bytes.
Continue readingConvert Hex to String in Python
This is a tutorial on how to convert hexadecimal numbers to strings in Python. When working with hex numbers, it can be difficult to read or compare them, so converting them to strings will make the process easier.
Continue readingAppend Text to a File in Python
Python offers several file access modes. One of them is “append”. This mode allows you to place the cursor at the end of the text file to insert the new lines there.
Continue readingRemove a String From a List in Python
Elements from the list (including strings) can be deleted using the remove() function.
Continue readingConvert String to JSON in Python
Function json.loads() accepts JSON string and converts it to Python dictionary (deserialization). The last letter in load(s) stands for “string”.
Continue readingHow to Write to Text File in Python
To write to a text file in Python, you have to use the open() and write() functions. The open() function takes two parameters: file name and file access mode. The returned value of open() is the file object.
Continue readingConvert CSV to a Dictionary in Python
To use CSV files in Python, you have to import the CSV module. It offers functions that can read the file (csv.reader) or read and map it to a dictionary (csv.DictReader).
Continue readingGet an Index of a String or Character in Python
The index and find functions return the position of a character or a substring inside a string. They both take a single parameter, that is required. The two additional parameters: __start and __end are optional.
Continue readingFind an Index of an Item in a List in Python
The index function returns the position of an item in a list. The function takes up to three parameters. One of them is required and the other two are optional.
Continue reading