Please enable JavaScript.
Coggle requires JavaScript to display documents.
working with text - Coggle Diagram
working with text
using files
opening files - file = open("testfile.txt", "w")
modes and buffers - Opening the file by just passing the filename to open() creates a read-only file object. If you want to be able to write to that file as well, it is necessary to set the optional mode argument. This argument can be a single character: r (read), w (write), or a (append),
reading from and writing to files - file = open("testfile.txt", "r")
print(file.read())
-
-
converting text
-
This type of conversion can also be done using the “%s” keyword, the .format function or using f-string function.
-
formatting data
-
print('I love {} for "{}!"'.format('Geeks', 'Geeks'))
-
"r" read file; "a" opens a file for appending, "w" opens file for writing, "x" creates the specified file
changing case
a = "Hello, World!"
print(a.lower())
-
remove wthitespace before and after the string a = " Hello, World! "
print(a.strip())
replace string
a = "Hello, World!"
print(a.replace("H", "J"))
-
-
-
finding string
-
txt = "Hello, welcome to my world."
-
-
-
regular expressions
A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern
-
-
-
-
-
-
-
-
-
-
-
-
-