In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to create and use strings in Python. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
String creation
Strings are the most commonly used data type in Python. We can use quotation marks ('or ") to create a string.
Creating a string is as simple as assigning a value to a variable.
Single and double quotation marks
We all know in Python that both single and double quotes can be used to represent a string, such as
Print ("What's your name?") Result: study hard and print ("python" is an excellent language). Result: "python" is an excellent language. A single quote is not a single quote, it is a format for string creation.
Generally speaking, there is no difference, only in single quotation marks when ordinary characters are easy to distinguish: such as var= "let's go"
Three quotation marks create block string long string
# three quotes to implement block comments "" document comments three quotes to implement block comments ""
String formatting
Convert a non-character type into a string
In Python, you can use the print function to output information to the console.
If you want to output text information as well as data, you need to use the formatting operator
% is called the format operator and is used specifically to handle formatting in strings
Contains a string of%, which is called a formatted string
% is used with different characters, and different types of data need to use different formatting characters
The syntax format is as follows:
Print ("format string s" >
% s
Align output
F
Embed a variable in a string
Name = "hello" f'{name}'
Case: cat's Eye top100
The website of Maoyan top100 has the following features:
Please use the three string construction methods to create all the request addresses
Member operator
In and not in are called member operators
The member operator is used to test whether the specified member is included in the sequence
The above is all the content of the article "how to create and use strings in Python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.