The Way To Read a String In Python

 What is String in Python?

A String represents a group of characters. The string is enclosed in double-quotes or single-quotes. The "str" data type represents a string. 

How to create a String in Python?

A string can be created by characters inside a single-quotes or double quote. Even triple quotes can be used to create a string that spans into serval lines.

                                                                                               Example- single quotes or double quotes




                     Output-   


Example- You can use three double quotes:


Output-

The print  list Statement Space-Separated element in Python

Python has no command for declaring a variable. we can also display the value of a variable using the print() function. To separate the output using the 'sep' attribute. The format is the sep="using characters" which are used to separate the value.

Example- Sep parameter in print()


Output-

The Print(Object) Statement
 
we can pass objects like lists, tuples to the print() function to display elements of those objects.

Example- Create Objects










Output-

The Print(Formatted String) Statement

The formatted string function has a special operator %(percent). It joins a string with a variable or value. In the "formatted string" we can use %i or %d to represent decimals integer number, %f represent float value, %s to represent a string.

Example- Formatted String Statement

Output-
 

Post a Comment

4 Comments

  1. It's really helpful as I just have started learning Python. Waiting for your blog on string methods of Python.

    ReplyDelete
    Replies
    1. First of sorry for late reply & thank you to show your interest on our post and python. We'll post all python related post soon according our reader's requirements.

      Delete