{"id":26672,"date":"2022-04-02T20:20:07","date_gmt":"2022-04-02T14:50:07","guid":{"rendered":"https:\/\/python-programs.com\/?p=26672"},"modified":"2022-04-02T20:20:07","modified_gmt":"2022-04-02T14:50:07","slug":"how-to-change-case-of-all-characters-in-a-txt-file-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/how-to-change-case-of-all-characters-in-a-txt-file-in-python\/","title":{"rendered":"How to Change Case of All Characters in a .txt File in Python"},"content":{"rendered":"
lower() Method:<\/strong><\/p>\n The lower() method in python returns a string with all characters in lower case. Symbols and numbers are ignored by this method.<\/p>\n upper() Method:<\/strong><\/p>\n The upper() method in python returns a string with all characters in the upper case. Symbols and numbers are ignored by this method.<\/p>\n Let us take a samplefile.txt as an Example here which contains the following content.<\/p>\n samplefile.txt:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n lower() Method: The lower() method in python returns a string with all characters in lower case. Symbols and numbers are ignored by this method. upper() Method: The upper() method in python returns a string with all characters in the upper case. Symbols and numbers are ignored by this method. Let us take a samplefile.txt as …<\/p>\nHello THIS is PYTHON-programs PLATform\r\nGOOd morning All<\/pre>\n
Converting All Characters in a Text File to Uppercase<\/h3>\n
\n
# Open some random file in read-only mode by passing filename\/path, mode as arguments to it. \r\ngvn_file = open('samplefile.txt', 'r')\r\n# Read the given file using read() function and loop through each letter of the text file\r\n# using the for loop\r\nfor k in gvn_file.read():\r\n # Convert each letter of the given text file to uppercase using the upper() function\r\n # and store it in a variable.\r\n res = k.upper()\r\n # Open some random new file in append mode using the open() function by passing file path, \r\n # mode as arguments to it. \r\n # Store it in another variable.\r\n output_file = open('output_file', 'a')\r\n # Append the above converted uppercase character to the new file using the write() function\r\n output_file.write(res)<\/pre>\n
HELLO THIS IS PYTHON-PROGRAMS PLATFORM\r\nGOOD MORNING ALL<\/pre>\n
Converting All Characters in a Text File to Lowercase<\/h3>\n
\n
# Open some random file in read-only mode by passing filename\/path, mode as arguments to it. \r\ngvn_file = open('samplefile.txt', 'r')\r\n# Read the given file using read() function and loop through each letter of the text file\r\n# using the for loop\r\nfor k in gvn_file.read():\r\n # Convert each letter of the given text file to lowercase using the lower() function\r\n # and store it in a variable.\r\n res = k.lower()\r\n # Open some random new file in append mode using the open() function by by passing file path, \r\n # mode as arguments to it. \r\n # Store it in another variable.\r\n output_file = open('output_file', 'a')\r\n # Append the above converted lowercase character to the new file using the write() function\r\n output_file.write(res)<\/pre>\n
hello this is python-programs platform\r\ngood morning all<\/pre>\n","protected":false},"excerpt":{"rendered":"