Movatterモバイル変換


[0]ホーム

URL:


2,064 views

Python Programming Essentials - M9 - String Formatting

This document discusses string formatting in Python. It explains that Python uses placeholders like %s and %d to format strings with values. The % operator method of string formatting is deprecated in Python 3 and the str.format() method is recommended instead. The format() method allows accessing formatting arguments by position or name to customize the order and labels of values in formatted strings.

Embed presentation

http://www.skillbrew.com/SkillbrewTalent brewed by theindustry itselfString formattingPavan VermaPython Programming Essentials@YinYangPavan
© SkillBrew http://skillbrew.comFormatting strings2>>> name = "Monty Python">>> "Python is named after %s" % name'Python is named after Monty Python'>>> age = 12>>> "this cat is %d years old" % age'this cat is 12 years old'Python usesplaceholders toformat stringsStrings: %sNumbers: %dFloat: %f
© SkillBrew http://skillbrew.comFormatting strings (2)3>>> os = "Android">>> version = 4.2>>> "my phone uses %s %d" % (os, version)'my phone uses Android 4'>>> "The value of Pi is %f" % 3.141592'The value of Pi is 3.141592'>>> "The value of Pi is %.2f" % 3.141592'The value of Pi is 3.14'Use of % operator has been deprecated in Python 3.x
© SkillBrew http://skillbrew.comFormatting strings with % operator4Use of % operator has been deprecated in Python 3.x
© SkillBrew http://skillbrew.comformat() method5>>> 'this is a sample {0}'.format('string')'this is a sample string'str.format()Strings have an inbuilt method formatused to format strings
© SkillBrew http://skillbrew.comAccessing arguments by position6>>> os = 'Android'>>> version = 4.2>>> 'phone uses {0} version {1}'.format(os, version)'phone uses Android version 4.2'>>> 'version no:{1} os:{0}'.format(os, version)'version no:4.2 os:Android'>>> '{0} v{1} version {1}'.format(os, version)'Android v4.2 version 4.2'
© SkillBrew http://skillbrew.comAccessing arguments by name7>>> 'phone uses {os} version {ver}'.format(os='ios', ver=7.0)'phone uses ios version 7.0‘>>> 'phone uses {os} version {ver}'.format(ver=4.2, os='android')'phone uses android version 4.2'
© SkillBrew http://skillbrew.comResources String formatting exampleshttp://docs.Python.org/2/library/string.html#format-examples8
9

Recommended

PPT
Python ppt
PPTX
Python Exception Handling
PPTX
Python
PPTX
Python OOPs
PDF
Object oriented approach in python programming
PDF
Strings in Python
PPTX
Functions in Python
PPTX
Python-Inheritance.pptx
PDF
Strings in python
PPTX
Looping statement in python
PPTX
Introduction to php
PPTX
Introduction to python
PDF
Python programming : Classes objects
PDF
Introduction to Python
PPTX
Python | What is Python | History of Python | Python Tutorial
PDF
Python functions
PPTX
Chapter 05 classes and objects
PPTX
Python-Polymorphism.pptx
PPTX
Python-Encapsulation.pptx
PPTX
Python: Modules and Packages
PPTX
Beginning Python Programming
PDF
Python programming : Files
PPTX
File in C language
PDF
Python GUI
PPTX
Applets in java
ODP
Python Modules
PPTX
Loops PHP 04
PPT
Introduction to Python
PPTX
Python Programming Essentials - M8 - String Methods

More Related Content

PPT
Python ppt
PPTX
Python Exception Handling
PPTX
Python
PPTX
Python OOPs
PDF
Object oriented approach in python programming
PDF
Strings in Python
PPTX
Functions in Python
PPTX
Python-Inheritance.pptx
Python ppt
Python Exception Handling
Python
Python OOPs
Object oriented approach in python programming
Strings in Python
Functions in Python
Python-Inheritance.pptx

What's hot

PDF
Strings in python
PPTX
Looping statement in python
PPTX
Introduction to php
PPTX
Introduction to python
PDF
Python programming : Classes objects
PDF
Introduction to Python
PPTX
Python | What is Python | History of Python | Python Tutorial
PDF
Python functions
PPTX
Chapter 05 classes and objects
PPTX
Python-Polymorphism.pptx
PPTX
Python-Encapsulation.pptx
PPTX
Python: Modules and Packages
PPTX
Beginning Python Programming
PDF
Python programming : Files
PPTX
File in C language
PDF
Python GUI
PPTX
Applets in java
ODP
Python Modules
PPTX
Loops PHP 04
Strings in python
Looping statement in python
Introduction to php
Introduction to python
Python programming : Classes objects
Introduction to Python
Python | What is Python | History of Python | Python Tutorial
Python functions
Chapter 05 classes and objects
Python-Polymorphism.pptx
Python-Encapsulation.pptx
Python: Modules and Packages
Beginning Python Programming
Python programming : Files
File in C language
Python GUI
Applets in java
Python Modules
Loops PHP 04

Viewers also liked

PPT
Introduction to Python
PPTX
Python Programming Essentials - M8 - String Methods
PPTX
Python Programming Essentials - M7 - Strings
PPTX
Python Programming Essentials - M23 - datetime module
PPTX
Python Programming Essentials - M31 - PEP 8
PPTX
Python Programming Essentials - M21 - Exception Handling
PPTX
Python Programming Essentials - M4 - Editors and IDEs
PPTX
Python Programming Essentials - M1 - Course Introduction
PPTX
Python Programming Essentials - M40 - Invoking External Programs
PPTX
Python Programming Essentials - M44 - Overview of Web Development
PPTX
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
PPTX
Python Programming Essentials - M28 - Debugging with pdb
Introduction to Python
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M1 - Course Introduction
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M28 - Debugging with pdb

Similar to Python Programming Essentials - M9 - String Formatting

PPT
PPS_Unit 4.ppt
PPTX
Python Strings.pptx
PPTX
An Introduction To Python - Python Midterm Review
PPTX
Practice Program-1.pptx.
PPTX
Practice Python Program-1.pptx
PPTX
Python begginer Practice Program-1.pptx
PPTX
Python Programming-UNIT-II - Strings.pptx
PPTX
Data Formatting in Python data analytics .pptx
PDF
Unit 1-Part-3 - String Manipulation.pdf
PDF
Python Strings Format
PPTX
Python Strings and strings types with Examples
PDF
python_strings.pdf
PPTX
Python Strings and its Featues Explained in Detail .pptx
PDF
PPT
PPTX
Welcome vibrant-technology-navimumbai
PDF
Welcome vibrant-technology-navimumbai
PDF
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PPTX
foundation class python week 4- Strings.pptx
PPTX
1-Object and Data Structures.pptx
PPS_Unit 4.ppt
Python Strings.pptx
An Introduction To Python - Python Midterm Review
Practice Program-1.pptx.
Practice Python Program-1.pptx
Python begginer Practice Program-1.pptx
Python Programming-UNIT-II - Strings.pptx
Data Formatting in Python data analytics .pptx
Unit 1-Part-3 - String Manipulation.pdf
Python Strings Format
Python Strings and strings types with Examples
python_strings.pdf
Python Strings and its Featues Explained in Detail .pptx
Welcome vibrant-technology-navimumbai
Welcome vibrant-technology-navimumbai
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
foundation class python week 4- Strings.pptx
1-Object and Data Structures.pptx

More from P3 InfoTech Solutions Pvt. Ltd.

PPTX
Python Programming Essentials - M6 - Code Blocks and Indentation
PPTX
Python Programming Essentials - M29 - Python Interpreter and Files
PPTX
Python Programming Essentials - M25 - os and sys modules
PPTX
Python Programming Essentials - M24 - math module
PPTX
Python Programming Essentials - M27 - Logging module
PPTX
Python Programming Essentials - M20 - Classes and Objects
PPTX
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
PPTX
Python Programming Essentials - M35 - Iterators & Generators
PPTX
Python Programming Essentials - M11 - Comparison and Logical Operators
PPTX
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
PPTX
Python Programming Essentials - M22 - File Operations
PPTX
Python Programming Essentials - M18 - Modules and Packages
PPTX
Python Programming Essentials - M13 - Tuples
PPTX
Python Programming Essentials - M17 - Functions
PPTX
Python Programming Essentials - M15 - References
PPTX
Python Programming Essentials - M39 - Unit Testing
PPTX
Python Programming Essentials - M14 - Dictionaries
PPTX
Python Programming Essentials - M34 - List Comprehensions
PPTX
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M24 - math module
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M15 - References
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M12 - Lists

Recently uploaded

PDF
Agentic Intro and Hands-on: Build your first Coded Agent
PDF
[BDD 2025 - Mobile Development] Mobile Engineer and Software Engineer: Are we...
PDF
[BDD 2025 - Full-Stack Development] Digital Accessibility: Why Developers nee...
PDF
Accessibility & Inclusion: What Comes Next. Presentation of the Digital Acces...
PDF
Mulesoft Meetup Online Portuguese: MCP e IA
PDF
Dev Dives: Build smarter agents with UiPath Agent Builder
PDF
Cheryl Hung, Vibe Coding Auth Without Melting Down! isaqb Software Architectu...
PDF
[BDD 2025 - Artificial Intelligence] Building AI Systems That Users (and Comp...
PDF
Transforming Content Operations in the Age of AI
PDF
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
PDF
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
PPTX
Connecting the unconnectable: Exploring LoRaWAN for IoT
PDF
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
PDF
Cybersecurity Prevention and Detection: Unit 2
PDF
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
PDF
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
PDF
So You Want to Work at Google | DevFest Seattle 2025
PDF
5 Common Supply Chain Attacks and How They Work | CyberPro Magazine
PPTX
kernel PPT (Explanation of Windows Kernal).pptx
PDF
How Much Does It Cost To Build Software
Agentic Intro and Hands-on: Build your first Coded Agent
[BDD 2025 - Mobile Development] Mobile Engineer and Software Engineer: Are we...
[BDD 2025 - Full-Stack Development] Digital Accessibility: Why Developers nee...
Accessibility & Inclusion: What Comes Next. Presentation of the Digital Acces...
Mulesoft Meetup Online Portuguese: MCP e IA
Dev Dives: Build smarter agents with UiPath Agent Builder
Cheryl Hung, Vibe Coding Auth Without Melting Down! isaqb Software Architectu...
[BDD 2025 - Artificial Intelligence] Building AI Systems That Users (and Comp...
Transforming Content Operations in the Age of AI
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
Connecting the unconnectable: Exploring LoRaWAN for IoT
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
Cybersecurity Prevention and Detection: Unit 2
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
So You Want to Work at Google | DevFest Seattle 2025
5 Common Supply Chain Attacks and How They Work | CyberPro Magazine
kernel PPT (Explanation of Windows Kernal).pptx
How Much Does It Cost To Build Software
In this document
Powered by AI

This slide introduces the Skillbrew platform and the presenter, Pavan Verma, focusing on Python programming essentials.

Explains basic string formatting with examples using placeholders for strings (%s), numbers (%d), and float (%f).

Provides additional examples of string formatting, mentioning the use of % operator which is deprecated in Python 3.

Reiterates that the % operator for string formatting is deprecated in Python 3, stressing the need for alternatives.

Introduces the str.format() method for formatting strings with examples, showcasing its usage.

Demonstrates how to access formatting arguments by their position within the format() method with practical examples.

Explains how to access formatting arguments by names, allowing for more readable and manageable code.

Offers resources and examples for further understanding of string formatting in Python.

No content provided in this slide.

Python Programming Essentials - M9 - String Formatting

  • 1.
    http://www.skillbrew.com/SkillbrewTalent brewed bytheindustry itselfString formattingPavan VermaPython Programming Essentials@YinYangPavan
  • 2.
    © SkillBrew http://skillbrew.comFormattingstrings2>>> name = "Monty Python">>> "Python is named after %s" % name'Python is named after Monty Python'>>> age = 12>>> "this cat is %d years old" % age'this cat is 12 years old'Python usesplaceholders toformat stringsStrings: %sNumbers: %dFloat: %f
  • 3.
    © SkillBrew http://skillbrew.comFormattingstrings (2)3>>> os = "Android">>> version = 4.2>>> "my phone uses %s %d" % (os, version)'my phone uses Android 4'>>> "The value of Pi is %f" % 3.141592'The value of Pi is 3.141592'>>> "The value of Pi is %.2f" % 3.141592'The value of Pi is 3.14'Use of % operator has been deprecated in Python 3.x
  • 4.
    © SkillBrew http://skillbrew.comFormattingstrings with % operator4Use of % operator has been deprecated in Python 3.x
  • 5.
    © SkillBrew http://skillbrew.comformat()method5>>> 'this is a sample {0}'.format('string')'this is a sample string'str.format()Strings have an inbuilt method formatused to format strings
  • 6.
    © SkillBrew http://skillbrew.comAccessingarguments by position6>>> os = 'Android'>>> version = 4.2>>> 'phone uses {0} version {1}'.format(os, version)'phone uses Android version 4.2'>>> 'version no:{1} os:{0}'.format(os, version)'version no:4.2 os:Android'>>> '{0} v{1} version {1}'.format(os, version)'Android v4.2 version 4.2'
  • 7.
    © SkillBrew http://skillbrew.comAccessingarguments by name7>>> 'phone uses {os} version {ver}'.format(os='ios', ver=7.0)'phone uses ios version 7.0‘>>> 'phone uses {os} version {ver}'.format(ver=4.2, os='android')'phone uses android version 4.2'
  • 8.
    © SkillBrew http://skillbrew.comResourcesString formatting exampleshttp://docs.Python.org/2/library/string.html#format-examples8
  • 9.

Editor's Notes

  • #7 Positioning of arguments is critical (1st snippet and 2nd snippet in this slide)

[8]ページ先頭

©2009-2025 Movatter.jp