One: Head insert #!/usr/bin/env python
Declare the interpreter and tell the operating system what it means to explain
Two: variable \ character encoding
1 Development tools: Pycharm
2 print ("Hello World")
3 name= "Laowu" Name2=name
Print ("My name is", name)
Print (name,name2)
Three: Defining rules for variables
1 can be any combination of alphanumeric or underscore
2 The first character of a variable cannot be a number
3 reserved keywords cannot be used as variable names
4 conventions of variables:
1 no Pinyin
2 No Chinese
3python does not support defining constants, so conventions define constants in uppercase
Four: Character encoding and binary
Five: Python string connection method:
There are many string connections in Python, and today you write the code, and by the way, summarize:
1 the most primitive string connection: Str1 + str2
2 python new string connection syntax: STR1, STR2
3 Strange string way: str1 str2
4% connection string: ' name:%s; Sex: '% (' tom ', ' Male ')
5 String List connection: Str.join (some_list)
First, presumably as long as the programmer has the experience of the people, it is estimated that the direct use of "+" to connect two strings:
' Jim ' + ' Green ' = ' jimgreen '
The second is special, if two strings are separated by "comma", then the two strings will be concatenated, but there will be a space between the strings:
' Jim ', ' green ' = ' Jim Green '
The third is also Python-specific, as long as the two strings together, the middle of a blank or no blank: two strings are automatically connected to a string:
' Jim ' Green ' = ' jimgreen '
' Jim ' Green ' = ' jimgreen '
The fourth function is more powerful, drawing on the function of the printf function in C, if you have a C language basis, look at the document to know. In this way, a string and a set of variables are concatenated with the symbol "%", and the special tags in the string are automatically replaced with the variables in the right variable group:
'%s ',%s '% (' Jim ', ' green ') = ' jim, green '
The fifth type is the technique, using the string function join. This function takes a list and then connects each element of the list with a string:
Var_list = [' Tom ', ' David ', ' John ']
A = ' # # # '
A.join (var_list) = ' tom## #david # # #john '
In fact, Python also has a way of string connection, but not much, is the string multiplication, such as:
A = ' abc '
A * 3 = ' abcabcabc '
Two Python variables and character encoding