Python - Formatting with Special Character

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;

1. Using (\n)

\n used to change lines

Source code.
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 code
print("\\")

The result.
\

3. Using a (,) comma. 

comma on python is used to separate a few sentences.

Source code.
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.
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.
print("My", "name", "is", sep="_", end="*")
print("Monty", "Python.", sep="*")


The result.
My_name_is*Monty*Python.*

6. Using (sep="")

0 Response to "Python - Formatting with Special Character"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel