#!/usr/bin/env Python3#-*-coding:utf-8-*-#Python StringVAR1 =' Day up'var2='Hello World'#the values in the string for the Python accessPrint("Var1[0]:", var1[0])Print("Var2[2:5]:", Var2[2:5])#updated Python stringPrint("Update string:", Var1[:3] +'Study hard! ')#The Python escape character#\ (at end of line) continuation character \a Bell \b Backspace#\e Escape \000 empty \v Portrait tab#\f \oyy octal number \XYY hexadecimal number#\other Other characters are output in normal format#commonly used: \ \ \ \ \ \ \ \ \#The Python string operator#+ String Connection * Duplicate output string [] get string character by index [:] intercept part of string#In/not in R/R raw string% format stringvar1=' Day up'var2='Hello World'Print("var1 + var2:", Var1 +var2)Print("var1 * 2:", VAR1 * 2)if 'to' inchvar1:Print("In the variable var1")Else: Print("var1 not in variable")#format of Python string#string built-in function of PythonVAR1 =' Day up'var2='Hello World'Print(Var2.capitalize ())#capitalize the first character of a stringPrint(Var1.capitalize ())Print(Var2.center (20,'-'))#returns the center of the original string and fills the new string with a space of length widthSub ="days"Print(Var1.count (Sub, 0, Len (var1)))#returns the number of occurrences of STR in a string, if beg or end specifies that the number of STR occurrences in the specified range is returnedPrint("str.upper ():", Var1.upper ())
Python Learning---strings