Python Learning---strings

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.