1.Print ()
In Python, the print() function is used to print the desired message on a device's screen. The Print is always in a string format. If the print message is in other objects, it is first converted into a string before being printed. You can input single or multiple objects of any type.
2.Simple print :
Print () is a function to take in values and print them. It just print the msg verbatim onto the screen.
print ("Hello World.! " )
3.F strings :
F strings allow you to embed expressions inside string literals, using curly braces { }
name: "python "
Print(f"welcome to {name} ")
4.Separator :
Sep stands for separator and is assigned a single space( ' ' ) by default.
Print("python ", "java" )
Print("python ", "java", sep="+" ) #python+java``
python java
5.end ="" White space
print("Python", end='@') print("kanniyam")
Output : python@kanniyam
6.Format :
The format() method formats the specified value(s) and insert them inside the string's placeholder. The placeholder is defined using curly brackets: {}.
Name ="Ranjith"
Age="23"
Print ("my name is { } I am { } year's old.". format (name) (age))
Output : my name is ranjith I am 23 year old
Print ("my name is {1 } I am {0 } year's old.". format (name) (age))
my name is 23 I am ranjith year old
print("The capital of (country) is (capital).".format(country France", capital-"Paris")) The capitalit France is faris
7 Str concatenate :
concatenate two are more strings with +
`Temperature = 100.0
Print (" the temperature is" +str(100.0) +"degree")
a = "Hello"
b = "World"
c = a + " " + b
print(c)
Output : Hello world
`
8.Multiple prints:
Multiple objects can also be printed within one print() when passed as a comma-separated list of parameters.
``name, age, city = "John", 30, "New York"
print(name)
print(age)
print(city)
Output:
John
30
New York``
9.Escape sequence :
\' Single Quote
\ Backslash
\n New Line
\r Carriage Return
\t Tab
\b Backspace
\f Form Feed
\ooo Octal value
\xhh Hex value
10.Printing qutoes inside string :
Single quotes
Single quotes (' ') are used to create strings and characters in Python programming.
s = 'Welcome to python '
print(s)
print(type(s))
Output :
Welcome to python
Double quotes:
We can also use the Double quotes (" ") to create strings and characters. The functionality of single (') and double (") quotes is the same; you can use either one depending on your requirements.
Double quotes in python programming
<class 'str'>
programming
<class 'str'>
12 Triple quotes:
The Triple quotes are used for commenting and representing the docString in the python.
`string = "Hello world"
'''The triple quotes are mainly used
for commenting the lines in python programming language'''
print(string)
Output:
The following is the output of the triple quotes used for commenting the lines. In the output we can see that the lines given in the triple quotes are not displayed in the output.
Hello world`
.
13.Raw string:
An ‘r’ before a string tells the Python interpreter to treat backslashes as a literal (raw) character. Normally, Python uses backslashes as escape characters.
Input: r'Python\nis\easy\to\learn'
Output: Python\nis\easy\to\learn
14 Printing numbers:
combating int and string in printing:
`name = "John"
age = 30
print("My name is " + name + " and I am " + str(age)
My name is John and I am 30 years old.
15.Multiline Strings:
You can assign a multiline string to a variable by using three quotes:
`
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
16 Multiple strings:
In Python, you can use the * operator to multiply not only numbers but also lists and strings.
`2*'string'
Output: stringstring`
Dat2 Agenda :
Yt Playlist:
Link :https://www.youtube.com/live/zr3skBHzbAI?si=6mXcArj8-33hBgLt
Solution:
https://youtu.be/k6pwbOZtQ30?si=iWYv8b3Lv5leCYWY
Top comments (0)