Python - Formatting with Special Character
Wednesday, July 3, 2019
Add Comment
Python - Formatting with Special Character.
Formatting with Special Character. This time we will learn how to format special characters in python. there are several special characters that can be used with different functions. As for the special characters are as follows:
- `\' = special character 'escaping nature'
- \n = for 'enter'
- \ = escaping characters
See the following guide for use;
Source code.
1. Using (\n)
\n used to change lines
print("Baa, baa black sheep\nHave you any wool.") print() print("Yes sir, yes sir\nThree bags full.")
The result.
Baa, baa black sheep Have you any wool. Yes sir, yes sir Three bags full.
2. Using (\), how to print backslash (\) in python?
Source codeprint("\\")
The result.
\
3. Using a (,) comma.
comma on python is used to separate a few sentences.
print("The itsy bitsy spider" , "climbed up" , "the waterspout.")
The result.
The itsy bitsy spider climbed up the waterspout.
4. Using (end=' ')
end=' ' used to put an argument after the first argument.
Source code.
Source code.
print("Hello", "My name is Python.", end=" ") print("Hard Work.")
The result.
Hello My name is Python. Hard Work.
5. Using (sep="")
sep=(" ") used to separate arguments from empty strings or other characters.
Source code.
Source code.
print("My", "name", "is", sep="_", end="*") print("Monty", "Python.", sep="*")
The result.
My_name_is*Monty*Python.*
0 Response to "Python - Formatting with Special Character"
Post a Comment