The first day of learning - variables and strings

A variable

1, the contact person for the program variables should not be unfamiliar. Baidu Encyclopedia defined variables are: Variable from mathematics, computer languages ​​can store the results or values ​​can be represented abstract concepts. I feel that variable to the data we need to get a code to facilitate data we call the variables associated

Like before "! Hello World" string, we can assign it to a variable message, and print message:

 

 

 2, variable naming ·

Naming variables, and other programming languages ​​feel very much the same:

(1) variable names contain only alphanumeric characters and underscores (python, of course, you can also use Chinese as a variable name, but it looks like not too formal, with the Chinese who have not seen variable names), the first character variable names should not be a letter or an underscore digital

(2) variable name can not be the same keywords and function names (like print)

(3) the best English transliteration, easy to read code and calls, of course, need and yet brief descriptive

(4) try to avoid using the I and O 1 and 0 as easily as

 Second, the string

Python provides several types of data, such as strings, numbers, a list of tuples, dictionaries

1, the basic use of the string

Of course, the character string is a series of single and double quotes in Python is not much difference between the three quotes, then you can use at the time of interbank

 

 

 

 2, the method of the string

The method of operation is performed on the data (of course, this is just Transcription on, I also explain do not understand is that some of the data processing, feeling a bit like a function call, here is the method of data calls, of course, is relatively simple in after adding variable data or method name, in pycharm in when we add in the data or variable. method will automatically prompt

 

 Here only some of the commonly used methods of learning

(1)title()

The initial capital letters for display

如message.title()

 

 

 

 (2) upper () and lower ()

upper: string all uppercase

lower: Processing all lowercase string

 

 

 3, splice string

Splicing python string comparison straightforward two strings "+" like

 

 

 

 4, tab and newline

Include tabs \ t a tab blank string

Newline \ n As the name suggests wrap

5, delete blank

Use string method rstrip, lstrip, strip. Delete the end of the beginning, both ends of the blank

 

Guess you like

Origin www.cnblogs.com/xiaobai-yang/p/11598859.html