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

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.