WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tutorial/string-formatting.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Formatting strings and output
==============================
Examples in Python 3

str.format() in Python 3

```python
"""
Expand Down Expand Up @@ -31,8 +30,25 @@ print("{0:10}{1:10}".format("Hello", "World"))


```
f-string formatting in Python 3
```python
"""
Python 3.6 added support for new kind of formatting.
"""
# The syntax is similar to the one you used with str.format() but less verbose and also faster.
name = "John"
f"Hello, {name}"

# F-strings are evaluated at runtime, you can put any and all valid Python expressions in them.
f"1 + 1 = {1+1}"

# You could also call functions
def to_lowercase(string):
return string.lower()

f"My name is {to_lowercase("John")} at lower-case"

```

Reference and read more
------------------------------
Expand Down