Home>Article>Backend Development> How to enter a string in Python
First of all, to display a string, just print (string) to display it.
Strings can use single quotes or double quotes. There is no character type in python.
Writing multiple strings directly together indicates connection. The escaping inside the string is similar to C.
Line break\n can be escaped, or line breakable text can be written between three quotation marks.
The string itself can access its fragments using subscripts.
As shown in the figure [0] represents the 0th character (beginning);
[0:1] represents from after 0 (including 0) to before 1 (excluding 1), and [ 0] The result is the same;
[5:] means everything after 5.
[:-3] means from the beginning to before the third to last character (excluding the third to last).
#Input uses input function, the usage is as shown in the figure.
A string can be multiplied by an integer to indicate how many times it is repeated, and another string can be added to indicate splicing.
\n\t within the string are escaped by default. If r is added before the string, they will not be escaped. (Similar to the @ prefix in C#)
The print function is responsible for output, and the end character can be set by end=xxx. The default end character is line break. If end is set to empty, there will be no line break.
print can also set sep=xxx, which represents the separator between multiple objects to be printed.
About the basic usage of pycharm: If it is a code py file, directly click the execution menu bar, or the run menu above, you can input and output in the console below.
If you switch to the Python console panel, it is the interactive mode of python.
For more Python related technical articles, please visit thePython Tutorial Columnto learn!
The above is the detailed content of How to enter a string in Python. For more information, please follow other related articles on the PHP Chinese website!