Python command line mode-basic operations, variables, strings

 

table of Contents

1. Basic operations

Two, variables

Numerical variables

Character variable

Three, string

Character function: capitalize the first letter of the string (title()), all uppercase (upper()), and all lowercase (lower())

Escape characters: \n, \t

String interception

Delete the margins on both sides of the string: rstrip(), lstrip(), strip()

Number to string: str()


The shortcut key win+R opens the dos window and executes the py command to enter the Python command line mode

Use Ctrl+Z to exit the command line

1. Basic operations

Addition, subtraction, multiplication and division, rounding (round function), high power (**)

Two, variables

Numerical variables

Use variable assignment operations

Character variable

Three, string

Character function : capitalize the first letter of the string (title()), all uppercase (upper()), and all lowercase (lower())

Escape characters : \n, \t

String interception

Delete the margins on both sides of the string: rstrip(), lstrip(), strip()

  • rstrip(): delete the margin on the right side of the string
  • lstrip(): delete the margin on the left side of the string
  • strip(): Remove the margins on the left and right sides of the string

Number to string: str()

age = 22
msg = "我今年" + str(age) + "岁"

print(msg)

 

Guess you like

Origin blog.csdn.net/qq_40323256/article/details/112143190