Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use variables in python string

Shulou Source: shulou.com Published: 2022-06-03 13:50:26 09月15日 Update

This article will explain in detail how to use variables in the python string. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. To insert the value of a variable in a string, you can add the character f before the quotation marks, and then put the variable to be inserted in curly braces. When Python displays a string, each variable is replaced by it.

2. This kind of string is called the f string, which is the abbreviation of format.

Example

First_name = "tom" last_name = "jerry" full_name = f "{first_name} {last_name}" print (f "Hello, {full_name.title ()}!") # title displays the word # output:# Hello,Tom Jerry in uppercase! This is the end of the article on "how to use variables in the python string". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Characters strings variables articles more good practical content words capitals letters examples quotes parentheses articles methods knowledge abbreviations quantities references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Shulou Tech Info macOS MySQL