mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
Merge pull request #1676 from vipulroxx/patch-1
Modified string format [python/en]
This commit is contained in:
commit
ba4cbab87a
@ -123,8 +123,12 @@ not False # => True
|
|||||||
# A string can be treated like a list of characters
|
# A string can be treated like a list of characters
|
||||||
"This is a string"[0] # => 'T'
|
"This is a string"[0] # => 'T'
|
||||||
|
|
||||||
# % can be used to format strings, like this:
|
#String formatting with %
|
||||||
"%s can be %s" % ("strings", "interpolated")
|
#Even though the % string operator will be deprecated on Python 3.1 and removed
|
||||||
|
#later at some time, it may still be good to know how it works.
|
||||||
|
x = 'apple'
|
||||||
|
y = 'lemon'
|
||||||
|
z = "The items in the basket are %s and %s" % (x,y)
|
||||||
|
|
||||||
# A newer way to format strings is the format method.
|
# A newer way to format strings is the format method.
|
||||||
# This method is the preferred way
|
# This method is the preferred way
|
||||||
|
Loading…
Reference in New Issue
Block a user