Monday, December 24, 2018

Learn Python from Zero to Hero Part 4

Hello World,
                        This is the Fourth part of the Python Tutorial series Learn Python from Zero to Hero, If you want to Learn Python from ZERO, Check my previous part of this tutorial series, Click the given link below.

Learn Python from Zero to Hero Part 1.
Learn Python from Zero to Hero Part 2.
Learn Python from Zero to Hero Part 3.

String Formatting in Python :

                        Python is the rich programming language, It is the collection of rich feature of programming , It is the real world programming like Java, Now here is the one of the best rich feature of Python that is String Formatting, String formatting is one of the best feature of Python Which I personally loved.
So let's see

Whats is String Formatting ? :

                        Let me explain string formatting in a very short description, String Formatting allows multiple substitution and value formatting. This string formatting in Python uses the format() method for string formatting in Python 3.

There are different syntax of string formatting in Python for different version, The Python 3 version have different way and Python 3.6 have it's own way of using string formatting, Both version of Python have different syntax, Let's take a look How String Formatting uses in Python ?.

# String Formatting in a Common way.
         name, age ="Syntaxios","2017"
              print("Name : "+name+" Age : "+age)

String Formatting in Python 3 :

# String Formatting in Python 3.
        name,age = "Be Syntaxios","18"
               print("Name : {} and Age : {}".format(name,age))
Here if you change the order, You got a different output.
              print("Name : {} and Age : {}".format(age,name))

Here {} boxes are called Placeholder, Sometimes It also known as Black Boxes.

String Formatting in Python 3.6 :

# String Formatting in Python 3.6.
               name, age = "syntaxios.blogspot.com","23"
                       print(f"Name is {name} and Age is {age}")        # don't forget to add 'f ' at starting.

# String Formatting in Python 3.6.
               name, age = "Aman Singh Rajawat",22
                     print("Name is : %s"%name)    #Single Variable
                       print("Name %s  and Age %d "%(name,age))     #Multiple Variables

Here %s stands for String and %d stands for Integer.

At Last Thanks for Reading and Don't be cheap to share with others...

If You have any question related to this post, Let me know in the comment section.

Previous Topic : Part 3                                                                                                                                                                                   Next Topic : String Methods                               
, , , , , ,

4 comments:


  1. I just wanna say Awesome

    ReplyDelete
  2. The best tutorial

    ReplyDelete
  3. Great Content.looking forward for more..

    ReplyDelete
  4. Sophisticated and simple alluring posts with latest updates.literally a tech beginners entry point to the technological world.

    ReplyDelete