Looks like you want repr()

>>> """skip
... line"""
'skip\nline'
>>>
>>> print(repr("""skip
... line"""))
'skip\nline'
>>> print(repr("skip    line"))
'skip\tline

So, your function could be

print_all = lambda s: print(repr(s))

And for Python 2, you need from __future__ import print_function

Answer from OneCricketeer on Stack Overflow
Discussions

Printing a range of characters after a specific character in a string
Use rindex to get the rightmost '.' and take the string from there on: def file_ending(name: str) -> str: last_dot: int = name.rindex('.') # raises ValueError if dot not in the filename return name[last_dot:] or shorter: def file_ending(name: str) -> str: # raises ValueError if dot not in the filename return name[name.rindex('.'):] More on reddit.com
🌐 r/learnpython
12
0
October 13, 2022
Python: How can you print strings one character at a time?
I guess I have to define a function for the print that uses time, which has a sleep(0.02) between each character. Maybe using a loop to pick out each len() in the text and print them? Or convert the string into a list and print it that way? Very new to python so all help appreciated. More on teamtreehouse.com
🌐 teamtreehouse.com
2
August 17, 2018
Python: print specific character from string - Stack Overflow
How do I print a specific character from a string in Python? I am still learning and now trying to make a hangman like program. The idea is that the user enters one character, and if it is in the word, the word will be printed with all the undiscovered letters as "-". More on stackoverflow.com
🌐 stackoverflow.com
Remove all "non-printable" characters.

There's probably a more efficient way, but you could loop over the string character by character and build up a new copy composed of only the characters which are in string.printable.

More on reddit.com
🌐 r/learnpython
4
2
November 16, 2014
🌐
W3Schools
w3schools.com › python › python_strings.asp
Python Strings
However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string. Get the character at position 1 (remember that the first character has the position 0): a = "Hello, World!" print(a[1]) Try it Yourself » · Since strings are arrays, we can loop through the characters in a string, with a for loop.
🌐
Tutorial Gateway
tutorialgateway.org › python-program-to-print-characters-in-a-string
Python Program to Print Characters in a String
December 19, 2024 - # Python program to Print Characters in a String str1 = input("Please Enter your Own String : ") for i in range(len(str1)): print("The Character at %d Index Position = %c" %(i, str1[i]))
🌐
Replit
replit.com › home › discover › how to print each character of a string in python
How to print each character of a string in Python | Replit
1 week ago - The print() function then outputs that character, moving to the next one in the following iteration until the string is exhausted. Beyond the straightforward for loop, Python offers other methods like enumerate(), while loops, and list comprehensions for when you need more control.
🌐
Reddit
reddit.com › r/learnpython › printing a range of characters after a specific character in a string
r/learnpython on Reddit: Printing a range of characters after a specific character in a string
October 13, 2022 -

SO, my code is

filename = input("File name: ")
if filename.endswith (".html"):
    print("This is an HTML file.")
else:
    print("This is a", filename[7:11], "file.")

If I input "whateva.jpg", it returns "This is a .jpg file.", because it prints the 7th to 11th characters from the input. But this only works when the input is a specific length. What I want is to be able to input a file name of any length, followed by any file type, and have it print "This is a .whateverTheFileTypeIs file."

Is there a way to have it split the input from whatever character comes before the period in the file type, and print from the period onwards? So if I input abcd.pdf, it'll return "This is a .pdf file", or if I input abcdefghijklmnop.docx, it'll print "This is a .docx file."?

I'm new so sorry if i'm not articulating this too well. Any help will be much appreciated

🌐
CodeSpeedy
codespeedy.com › home › print each character of a string one at a time in python
Print Each Character of a String in Python one at a time - CodeSpeedy
April 24, 2019 - We printed each character one by one using the for loop. import time this_string = "Hey I am CodeSpeedy" for character_index in this_string: print(character_index) # print each character at a time from string time.sleep(0.5)
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › How-to-print-characters-from-a-string-starting-from-3rd-to-5th-in-Python
How to print characters from a string starting from 3rd to 5th in Python?
May 29, 2025 - Following is an example to print characters from a string starting from the 3rd to the 5th by using the indexing and slicing - # introducing a string String = 'TutorialsPoint' # To get the string starting from thrd to fifth print(String[2:5]) ... In Python, Negative Indexing is used to access elements from the end of a list, tuple, or string.
🌐
YouTube
youtube.com › shorts › XknOm5OI5Dw
How to print Each Letter of a String in Python #shorts - YouTube
How to print Each Letter of a String in Python#shorts#python
Published   July 13, 2021
🌐
PyTutorial
pytutorial.com › for-each-character-in-string-python
PyTutorial | Print each Character of a String in Python
January 6, 2023 - Printing each character of a string in Python can be achieved through various methods, including for loops, while loops, list comprehension, and the join() method.
🌐
Educative
educative.io › answers › how-to-get-the-characters-in-a-string-in-python
How to get the character(s) in a string in Python
# To also get all the characters of the string · print(Name[:]) Run · When you use the syntax print(Name[0:]), Python will assume the indexes from zero to the last index by default. The same applies to print(Name[:6]) and print(name[:]); Python will assume the indexes from zero to the 5th index and from zero to the last index, respectively.
🌐
Quora
quora.com › How-do-you-print-every-other-letter-in-a-string-in-Python
How to print every other letter in a string in Python - Quora
Answer (1 of 5): It’s as simple as this: [code]my_string = "Something Cool" print(my_string[::2]) >> SmtigCo [/code]Or if your string isn’t stored in a variable: [code]"Something Cool"[::2] >> SmtigCo [/code]Hope this helped! Don’t forget there is always help when you need it, if you have an...
🌐
IncludeHelp
includehelp.com › python › access-and-print-characters-from-the-string.aspx
Python | Access and print characters from the string
# first 5 characters print "str[0:5]:", str[0:5] # print characters from 2nd index to 2nd last index print "str[2,-2]:", str[2:-2] # print string character by character print "str:" for i in str: print i, #comma after the variable # it does not print new line ... str: Hello world str[0]: H str[1]: e str[-1]: d str[-2]: l str[0:5]: Hello str[2,-2]: llo wor str: H e l l o w o r l d ... Comments and Discussions! ... D.S. Programs ... Copyright © 2025 www.includehelp.com. All rights reserved.
🌐
STEMpedia
ai.thestempedia.com › home › examples › print characters in word python using for loop
Print Characters in Word PYTHON using For Loop - Example Project
July 31, 2023 - #Print the characters in word PYTHON using for loop for letter in 'PYTHON': print(letter) The code uses a for loop to iterate through the letters in the string “PYTHON”. For each letter, the print statement is executed to display it on the ...
🌐
Quora
quora.com › How-do-you-print-a-single-character-from-a-string-in-Python
How to print a single character from a string in Python - Quora
To get a character as a string of length 1 (usual case): indexing returns that already. To convert to a character code: ord(s[0]) → integer Unicode code point. To get a character from a code point: chr(97) → 'a'. ... Slicing returns substrings (possibly length 1): s[2:3] → 'l' (useful when avoiding IndexError in some patterns). Performance: indexing is O(1). Use indexing when you need a specific position; iterate for all characters.
🌐
Google
developers.google.com › google for education › python › python strings
Python Strings | Python Education | Google for Developers
If you want integer division, use 2 slashes -- e.g. 6 // 5 is 1 · The "print" function normally prints out one or more python items followed by a newline. A "raw" string literal is prefixed by an 'r' and passes all the chars through without special treatment of backslashes, so r'x\nx' evaluates to the length-4 string 'x\nx'.
🌐
GeeksforGeeks
geeksforgeeks.org › python › iterate-over-characters-of-a-string-in-python
Iterate over characters of a string in Python - GeeksforGeeks
July 11, 2025 - If we need both the character and its index then enumerate() is a great choice. It returns both values in each iteration. ... The print function uses a formatted string, where the f before the string allows us to include variables directly within ...