Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Scripting >> Python >> Examples >> Strings >> Functions (methods) for the string

 

Method Description Sample code
str.capitalize() Return a copy of the string S with only its first character
capitalized
>>> var="hello"
>>> var.capitalize()
'Hello'
str.format()

Return a formatted version of S, using substitutions from args and kwargs.  The substitutions are identified by braces ('{' and '}')

Syntax: str.format(*args, **kwargs) -> string

  • args = Positional parameters - list of parameters that can be accessed with index of parameter inside curly braces {index}
  • kwargs = Keyword parameters - list of parameters of type key=value, that can be accessed with key of parameter inside curly braces {key}

Example 1
>>> x=1
>>> y=2
>>> s=x+y
>>> print("{} + {} = {}".format(x,y,s))
1 + 2 = 3

Example 2
>>> print "{x} + {y} = {s}".format(x=1,y=2,s=x+y)
1 + 2 = 3
 

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

 

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]