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

PPTX
Chapter 05 classes and objects
PDF
Variables & Data Types In Python | Edureka
PDF
Class and Objects in Java
PPTX
Static Data Members and Member Functions
PPTX
Inline Functions and Default arguments
PPT
Abstract class in java
PPTX
Constructor in java
PPTX
Fundamentals of Python Programming
PPT
Python Programming ppt
PPTX
Python basics
PDF
Introduction to oops concepts
PPTX
Basics of Object Oriented Programming in Python
PPTX
OOP concepts -in-Python programming language
PPTX
File handling in Python
PDF
Python Programming
PPT
Final keyword in java
PPTX
Scope rules : local and global variables
PPTX
This pointer
PPTX
Iostream in c++
PPTX
Java method
PPT
Oops in Java
PPT
Method overriding
PPTX
Fragment
PDF
Java I/O
PDF
Threads concept in java
PPT
Applet life cycle
PPT
Introduction to Python
PPTX
Python Programming Essentials - M8 - String Methods

More Related Content

PPTX
Chapter 05 classes and objects
PDF
Variables & Data Types In Python | Edureka
PDF
Class and Objects in Java
PPTX
Static Data Members and Member Functions
PPTX
Inline Functions and Default arguments
PPT
Abstract class in java
PPTX
Constructor in java
Chapter 05 classes and objects
Variables & Data Types In Python | Edureka
Class and Objects in Java
Static Data Members and Member Functions
Inline Functions and Default arguments
Abstract class in java
Constructor in java

What's hot

PPTX
Fundamentals of Python Programming
PPT
Python Programming ppt
PPTX
Python basics
PDF
Introduction to oops concepts
PPTX
Basics of Object Oriented Programming in Python
PPTX
OOP concepts -in-Python programming language
PPTX
File handling in Python
PDF
Python Programming
PPT
Final keyword in java
PPTX
Scope rules : local and global variables
PPTX
This pointer
PPTX
Iostream in c++
PPTX
Java method
PPT
Oops in Java
PPT
Method overriding
PPTX
Fragment
PDF
Java I/O
PDF
Threads concept in java
PPT
Applet life cycle
Fundamentals of Python Programming
Python Programming ppt
Python basics
Introduction to oops concepts
Basics of Object Oriented Programming in Python
OOP concepts -in-Python programming language
File handling in Python
Python Programming
Final keyword in java
Scope rules : local and global variables
This pointer
Iostream in c++
Java method
Oops in Java
Method overriding
Fragment
Java I/O
Threads concept in java
Applet life cycle

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

PDF
Strings in Python
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
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
Strings in Python
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.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 - M24 - math module
PPTX
Python Programming Essentials - M25 - os and sys modules
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 - M24 - math module
Python Programming Essentials - M25 - os and sys modules
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
[BDD 2025 - Full-Stack Development] Digital Accessibility: Why Developers nee...
PDF
Parallel Computing BCS702 Module notes of the vtu college 7th sem 4.pdf
PDF
Mulesoft Meetup Online Portuguese: MCP e IA
PDF
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
PDF
[BDD 2025 - Full-Stack Development] Agentic AI Architecture: Redefining Syste...
PDF
ODSC AI West: Agent Optimization: Beyond Context engineering
PDF
Dev Dives: Build smarter agents with UiPath Agent Builder
PDF
Mastering UiPath Maestro – Session 2 – Building a Live Use Case - Session 2
PDF
Transforming Content Operations in the Age of AI
PDF
Transcript: The partnership effect: Libraries and publishers on collaborating...
PDF
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
PDF
[BDD 2025 - Mobile Development] Crafting Immersive UI with E2E and AGSL Shade...
PDF
The Evolving Role of the CEO in the Age of AI
PDF
KMWorld - KM & AI Bring Collectivity, Nostalgia, & Selectivity
PPTX
The power of Slack and MuleSoft | Bangalore MuleSoft Meetup #60
PDF
The Necessity of Digital Forensics, the Digital Forensics Process & Laborator...
PPTX
Connecting the unconnectable: Exploring LoRaWAN for IoT
PPTX
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
PDF
10 Best Automation QA Testing Software Tools in 2025.pdf
PDF
"DISC as GPS for team leaders: how to lead a team from storming to performing...
 
[BDD 2025 - Full-Stack Development] Digital Accessibility: Why Developers nee...
Parallel Computing BCS702 Module notes of the vtu college 7th sem 4.pdf
Mulesoft Meetup Online Portuguese: MCP e IA
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
[BDD 2025 - Full-Stack Development] Agentic AI Architecture: Redefining Syste...
ODSC AI West: Agent Optimization: Beyond Context engineering
Dev Dives: Build smarter agents with UiPath Agent Builder
Mastering UiPath Maestro – Session 2 – Building a Live Use Case - Session 2
Transforming Content Operations in the Age of AI
Transcript: The partnership effect: Libraries and publishers on collaborating...
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
[BDD 2025 - Mobile Development] Crafting Immersive UI with E2E and AGSL Shade...
The Evolving Role of the CEO in the Age of AI
KMWorld - KM & AI Bring Collectivity, Nostalgia, & Selectivity
The power of Slack and MuleSoft | Bangalore MuleSoft Meetup #60
The Necessity of Digital Forensics, the Digital Forensics Process & Laborator...
Connecting the unconnectable: Exploring LoRaWAN for IoT
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
10 Best Automation QA Testing Software Tools in 2025.pdf
"DISC as GPS for team leaders: how to lead a team from storming to performing...
 
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