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.
So let's see
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 ?.
At Last Thanks for Reading and Don't be cheap to share with others...
Artificial Intelligence
,
Beginners
,
Data Science
,
Machine Learning
,
Python
,
Python Tutorial
,
Web Development
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"
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))
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 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...
I just wanna say Awesome
ReplyDeleteThe best tutorial
ReplyDeleteGreat Content.looking forward for more..
ReplyDeleteSophisticated and simple alluring posts with latest updates.literally a tech beginners entry point to the technological world.
ReplyDelete