Python’s built-in functions related to strings
Built-in functions are predefined functions in programming languages, which can greatly improve the efficiency of programmers and the readability of programs. Let’s look at a few commonly used built-in functions.
The print() function displays the strings enclosed in parentheses on the screen, and these strings to be printed are the arguments to print().
>>> print("Hello World!") Hello World! >>> print("What is your name?")
What is your name?
Tip: The parameters of a function are the values used to run the function when the function is called. When calling the function, the parameters are generally placed in parentheses after the function.
The input() function waits for the user to enter some text on the keyboard and press the enter key, thus getting the text entered by the user.
In the following example, we use the input() function to first assign the input string to the variable myName, and then call the print() function, including the expression “My Name is” + myName in parentheses, and then we can concatenate The string is output to the screen.
>>> myName=input() Johnson >>> print ("My name is "+myName) My name is Johnson
You can pass a string (or a variable containing a string) to the len() function, which returns an integer value representing the number of characters in the string.
>>> len("Hello") 5 >>> myName="Johnson" >>> len(myName) 7