How to Format String in Python | EP-27 String Formatting in Python | Python Tutorials

Subscribers:
27,900
Published on ● Video Link: https://www.youtube.com/watch?v=M9cqucE5v3Q



Duration: 0:00
70 views
2


String Formatting
"""String formating is also known as string interpolation.
Interpolation:String interpolation is a process substituting values of variables into
placeholders in a string. For instance, if you have a template for saying hello to a person
like "Hello {Name of person}, nice to meet you!", you would like to replace the placeholder
for name of person with an actual name.
string formatting can be done in various ways
1.% formatting
2. str.formate()function
3. f-string"""

1. % formatting
"""Oldest technique used to insert an object into a string."""
company = "cybrosys"
city= "calicut"
print("Company name is %s." %company)

"""Multiple values are allowed in string formatting"""
print("Company name is %s and located at %s."%(company,city))


2. str.formate()function
"""The placeholders are replaced by curly braces in this technique"""
company = "cybrosys"
city= "calicut"
print("Company name is {} and located at {}.".format(company,city))

"""Refering variable through indexing is possible"""
company = "cybrosys"
city= "calicut"
print("Company name is {0} and located at {1}. ".format(company,city),":indexing")

"""to improve the readability,keyword also used"""
C = "cybrosys"
c = "calicut"
print("Company name is {Company} and located at {City}. ".format(Company=C,City=c),"::::::::")

"""Formate specifies like f for float, b for binary , d for integers can be used"""
print("I have scored {:f}% mark in english".format(55.66))

"""An integer can be provided in place of float but float cannot be provided in place of
integer"""
print("I have scored {:f}% mark in maths".format(55))
print("I have scored {:d}% mark in english".format(55))


"""Providing a sting in place of float will result in an error"""
print("I have scored {:d}% mark in english".format('55'))


"""The length of value after the decimal point can be controlle"""
print("I have scored {:.1f}% mark in maths".format(55.789654626549865))


3. f-string
"""used to format a string
syntax : f"string{object} """
company = "cybrosys"
city= "calicut"
print(f"company name is {company} and city is {city} ")
print(F'company name is {company} and city is {city}')

#PythonTutorials #StringFormatting #PythonForBeginners #LearnPython #CodingTips #PythonProgramming #Programming #PythonTricks #CodingTutorial #Developer #python #pythontutorial #coding #tutorial #pythontips #python3 #python2 #fstrings #formatmethod #percentformatting #pythondeveloper #datascience #machinelearning #deeplearning

Connect With Us:
—————————————
➡️ Website: https://www.cybrosys.com/
➡️ Email: info@cybrosys.com
➡️ Twitter:   / cybrosys  
➡️ LinkedIn:   / cybrosys  
➡️ Facebook:   / cybrosystechnologies  
➡️ Instagram:   / cybrosystech  
➡️ Pinterest:   / cybrosys  




Other Videos By Cybrosys Technologies


2024-08-21Revamped POS User Interface in Odoo 18 | Odoo 18 Revamped Point of Sale User Interface | Odoo 18 POS
2024-08-20How to Check if a Number is Even or Odd in Python| EP-30 Check Given Number is Even or Odd in Python
2024-08-20Odoo 18 Events PWA | Registration Desk Kiosk | Event Kiosk Mode in Odoo 18 | Odoo 18 New Features
2024-08-20How to Create Event Stages in Odoo 17 Events App | How to Manage Event Stages in Odoo 17 Events App
2024-08-19What is Boolean Data Type in Python | EP-29 Boolean Datatype in Python | Python Booleans| Data Types
2024-08-19Odoo 18 Marketing Card App | New App in Odoo 18 | Marketing Card in Odoo 18 | Odoo 18 New Features
2024-08-19How to Manage Your Company Budget Using Odoo 17 Accounting | Budget Management in Odoo 17 Accounting
2024-08-18What is a Numeric Data Type in Python | EP-28 Numeric Data Types in Python | Python Data Types
2024-08-18How to Create an Event in Odoo 17 Event App | Configure an Event in Odoo 17 Event |Odoo 17 Tutorials
2024-08-18Customer Statement Report in Odoo 18 | How to Generate Customer Statements Report in Odoo 18
2024-08-15How to Format String in Python | EP-27 String Formatting in Python | Python Tutorials
2024-08-13How to Create a Helpdesk Ticket in Odoo 17 | Odoo 17 Help Desk App | Odoo 17 Functional Tutorials
2024-08-13Odoo 18 Attendance Kiosk | Odoo 18 Attendance PWA | Odoo 18 New Features | Odoo 18 Tutorials
2024-08-12How to Configure Task Management in Odoo 17 Field Service | How to Manage Task Creation in Odoo 17
2024-08-12New Employee Login Screen in Odoo 18 POS | Odoo 18 Point of Sale | Odoo 18 New Features | Odoo 18
2024-08-11Bank Account Menu in Odoo 18 Employee App | Odoo 18 New Features | Latest Features in Odoo 18
2024-08-11How to Create Worksheet Template in Odoo 17 Field Service | Customize Worksheet in Odoo 17
2024-08-08How to Capitalize Each String in a List of Strings in Python | EP-26 String Capitalize() Method
2024-08-08How to Hide Seconds From Date Time Fields in Odoo 18 | Odoo 18 New Features |Odoo 18 Latest Features
2024-08-07How to Create Timesheets Report Using Odoo 17| Timesheet Reports in Odoo 17| Odoo 17 Tutorials
2024-08-07How to Apply Within Operator in Custom Filter in Odoo 18| Within Operator in Odoo 18 Domain Selector