python The use of single and double quotation marks in is exactly the same
Use three quotes (’’' or """) You can specify a multiline string
Escape character ‘’, You can enter special characters by escaping characters , Use r You can keep the backslash from escaping .. Such as r"this is a line with \n" be \n Will be displayed , It's not a new line .
String can be used + Operators join together , use * Operator repetition .
The syntax format of string truncation is as follows : Variable [ Header subscript : Tail subscript : step ]
str1='rootbook'
print(str1)
print(str1[0:-1])
# Natural numbers are counted from left to right , Negative numbers are counted from right to left
print(str1[0])# Output the first character
print(str1[2:])# Output all characters after the third
print(str1[[1:5:2])# The output starts from the second number to the fifth number and the retrieval interval is 2
print(str1*2)# Output string twice
print(str1+' Hello ')
stay python use import perhaps from…import To import the corresponding module .
The whole module (somemodule) Import , The format is : import somemodule
Import a function from a module , The format is : from somemodule import somefunction
Import multiple functions from a module , The format is : from somemodule import firstfunc, secondfunc, thirdfunc
Import all functions in a module into , The format is : from somemodule import *
import After import , When using functions in this module , Module name qualification required .
*from…import After import , There is no need to restrict the use of these functions
def show_num(num):
# The body of the function
print(num)
# Call function
show_num(100)
def show_num(num):
# The body of the function
print(num*3)
# Call function
show_num(100)
#select * from comment order