format string Python

Содержание
Введение
Синтаксис
Примеры
unichr
Похожие статьи

Введение

format string были доступны в Python 3.0 и описаны в PEP 3101

Синтаксис

str.format()

Примеры

name = "Alex Brezhnev" print("Hello, {}".format(name))

python2 format_ex.py

Hello, Alex Brezhnev

name = "Alex" url = "alexbrezhnev.ru" print("Hello, {n} your site is ready at {u}".format(n=name, u=url))

python2 format_ex.py

Hello, Alex your site is ready at alexbrezhnev.ru

print("My website name is {0[name]}, and address is {0[url]}".format(dict(name="AndreyOlegovich", url="www.aredel.com")))

python2 format_ex.py

My website name is AndreyOlegovich, and address is www.aredel.com

Пример генерации символов

Рассмотрим вывод Unicode символов с помощью функции unichr()

# Python 2 for i in range(128): print("unichr({counter}): {value}".format(counter=i, value=unichr(i)))

python format_string.py

unichr(0): unichr(1): … unichr(33): ! unichr(34): " unichr(35): # … unichr(64): @ unichr(65): A unichr(66): B unichr(67): C … unichr(97): a … unichr(122): z unichr(123): { unichr(124): | unichr(125): } unichr(126): ~ unichr(127):

Article author: Andrei Olegovich

Похожие статьи
Built-in Collections
Строки
Python
f-string
format string
encode()
Перенос слишком длинной строки на новую

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: