how to print bold font when using f-string?
It is the same as the regular string
Try this:
name = 'Yacoub'
age = 23
print(f"This is \033[1mbold\033[0m and my name is \033[1m{name}\033[0m\nI am \033[1m{age}\033[0m years old")
Output:
This is bold and my name is Yacoub
I am 23 years old
How can I make text bold in Python?
You might want to try ANSI escape sequences if your platform allows it.
Crossposting from related - and possible duplicate - SO questions: 1 2
Before you proceed, please read the warnings in the above links to make sure your operating system and Python version will allow you to properly render this.
You can define a class containing all of the ANSI escape sequences you need.
class style:
BOLD = '\033[1m'
END = '\033[0m'
Then print
them via concatenated class calls:
print style.BOLD + 'This is my text string.' + style.END
If you don't want to go through the hassle of creating an entire class just to get bold text, you can obviously concatenate them directly instead. However, if your code is open-source and not for personal use, make sure you tell other potential readers what this does!
print '\033[1m' + 'This is my text string.' + '\033[0m'
Does this answer your question?
Edit: JYelton beat me to it. I'm such a slow typer...
How to print bold text in python with ```format```?
The same ANSI escape sequences work just fine.
print('\033[1m{:10s}\033[0m'.format('foo'))
How to make bold text in python query?
The issue is caused by the way you pass the parse_mode.
In your url there is:
&parseMode=MarkdownV2
But that should be
&parse_mode=MarkdownV2
After changing that, it works as expected with the following url/code/output:
https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<CHAT-ID>&parse_mode=MarkdownV2&photo=http://placehold.jp/150x150.png&caption=*Foo*Bar
import requests
chatID='my-chat-id'
link='http://placehold.jp/150x150.png'
token='my-private-token'
caption='Example text'
telegram_msg = requests.get(f'https://api.telegram.org/bot{token}/sendPhoto?chat_id={chatID}&parse_mode=MarkdownV2&photo={link}&caption=*{caption}*')
Note: Make sure you're using Python 3.6 or above to use f
strings:
How do I put a variable’s value inside a string?
Related Topics
Repeat Rows in a Pandas Dataframe Based on Column Value
Libxml Install Error Using Pip
Seeing Escape Characters When Pressing the Arrow Keys in Python Shell
Check If a String in a Pandas Dataframe Column Is in a List of Strings
Keyerror: 'Tcl_Library' When I Use Cx_Freeze
Why Do Some Functions Have Underscores "_" Before and After the Function Name
How to Determine a Point Is Between Two Other Points on a Line Segment
How Does Perspective Transformation Work in Pil
Difference Between .String and .Text Beautifulsoup
Oserror [Errno 22] Invalid Argument When Use Open() in Python
Pylab.Ion() in Python 2, Matplotlib 1.1.1 and Updating of the Plot While the Program Runs
Installing Pip Packages to $Home Folder
What's the Fastest Way in Python to Calculate Cosine Similarity Given Sparse Matrix Data
Python: Count Repeated Elements in the List
Ssl.Sslerror: Tlsv1 Alert Protocol Version
How to Color Python Logging Output