Categories: Python

Python string Handling with example

Python string handling with example

In this tutorial , we will discuss the python string handling with example.

A string is a set of characters inorder. E.g.  a letter, number and symbol may become a character.

We can print a string many way using single quote , double quote and triple quote in python.

1. print(‘hello’)        //print using with single quote

2. print(“hello”)      // print using with double quotes

3. print(”’hello”’)     //print using with triple- single  quotes

4. print(“””hello”””) // print using with triple – double quotes

Output here

Example

We can print a string using single quote with variable.

5. first_string=’hello’          // assign a string to variable using single quote
print(first_string)           // print string with variable

We can print a string using double quote with variable.

6. second_string=”hello”   // assign a string to variable using double quote
print(second_string)       // print string with variable

We can print a string using triple – single quote with variable

7. third_string=”’hello”’      // assing a string to variable using triple – single quote
print(third_string)          // print string with variable

We can print a string using triple – double quote with variable

8. forth_string=”””hello”””    // assing a string to variable using triple – double quote
print(forth_string)              // print string with variable

Output here
Example

We can use the triple quote to print multiple line string

1. using triple – single quote to print multiple line string

multiple_line_string=”’hello
how
are
you”’      // assing a string to variable using triple – single quote
print(multiple_line_string)          // print string with variable

2. using triple – single quote to print multiple line string

multiple_line_string=”””hello
how
are
you”””   // assing a string to variable using triple – single quote
print(multiple_line_string)          // print string with variable

Code

Example
Output
Concatination of String
We can join two or more string in python, Known as concatination in python.
The plus operator (+) uses this operation for string
String concatination in python shell
Using + operator
Example
Concatination with two or more string using variable
Example
String concatination in python shell
Using single or double quotes
We can use single or double quotes to concatinate two or more string
Example
Multiplication of String
Multiplication of one string is called multiplication of string in python.
The multiply operator (*) uses this operation in string
Example

 

Karmehavannan

Share
Published by
Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.