This article is divided into six major categories:
About Python
Data type
Print statement
Comments
Variable
String
First, Python introduction:
python Features: Elegant, clear, concise
Python for development: Web
Python Pros: Less code, faster development
Python disadvantage: The original code cannot be encrypted
Python is a cross-platform programming language that can be run in a language other than a platform
Python version type: 2.7 3.6
Difference: The syntax is incompatible, the 2.7 version can be run directly on the 3.6 version;
Python installation (Windows): 2.7 Configuring environment variables
650) this.width=650; "title=" 1.png "src=" https://s2.51cto.com/wyfs02/M01/8F/AA/ Wkiol1joxsmg6cdbaaessslxfmu850.png-wh_500x0-wm_3-wmp_4-s_11139116.png "alt=" Wkiol1joxsmg6cdbaaessslxfmu850.png-wh_50 "/>
Python First Program:
Practice:
print "Hello World" on the screen and enter "exit ()" To complete the first Python program
650) this.width=650; "title=" 2.png "src=" https://s3.51cto.com/wyfs02/M02/8F/AA/ Wkiol1joyh2iyhtfaaazgufkcxe518.png-wh_500x0-wm_3-wmp_4-s_2976240073.png "alt=" Wkiol1joyh2iyhtfaaazgufkcxe518.png-wh_50 "/>
Interactive command-line disadvantage: file cannot be saved
Text file with file error ending with. py
Recommended software: Pycharm, nodepad++, never use Notepad, word (because there will be inexplicable errors)
Second, the data type:
1. Integral type
2. Floating-point type
3. Strings (String)
4. Boolean type (True,false)
5. Null value (None)
list, dictionary, custom--The following chapters will refer to
1. Integral type (integer)
Python can handle integers of any size, including negative integers
1,100,-1000,0
The computer uses the binary: 10101010
Hex: 0x and 0-9,a-f indicate for example: 0xff=255
Practice: Use decimal integer 10 to add hex 255 to print out the results;
Print (10+0XFF); 265
2. Floating-point type
Decimals, floating-point numbers can be written in scientific terms: 1230000000.0
For large or very small floating-point numbers, exponential power is used
1.23e9 exponent Power 1.23*10 9 times (less than 10)
Print (1.23e9); 1230000000.0
3. Strings (String)
Any text enclosed in "or" "abc" "XYZ" "10"
Print (' abc ');p rint ("xyz");
4. Boolean value type (True,false)
Boolean values can be represented directly in Python using True,false (note case)
--Practice: Can output Boolean values directly
650) this.width=650; "title=" 3.png "src=" https://s3.51cto.com/wyfs02/M01/8F/AC/ Wkiom1jozkzxc2cuaaagrru0nd4321.png-wh_500x0-wm_3-wmp_4-s_1045848161.png "alt=" Wkiom1jozkzxc2cuaaagrru0nd4321.png-wh_50 "/>
5. Null value (None)
Cannot be understood as 0, because 0 is meaningful, and none is a special null value
--Practice:
Please use a string to represent the welcome to Beijing
Computes the Boolean value of the following expression
100<90//?
0xff==255//?
(Note: = = Indicates whether equality is judged)
650) this.width=650; "title=" 4.png "src=" https://s1.51cto.com/wyfs02/M02/8F/AC/ Wkiom1jozd2z-vsiaaakjwtgba8396.png-wh_500x0-wm_3-wmp_4-s_3591743378.png "alt=" Wkiom1jozd2z-vsiaaakjwtgba8396.png-wh_50 "/>
Print statement
Syntax: print ();
Attention:
>>> is a Python interpreter prompt, not part of the code
Don't add >>> when editing
Print: Multiple strings can be printed, separated by commas, you can wind up a string of output;
--Exercise: Print out what colors your shirt?
650) this.width=650; "title=" 5.png "src=" https://s4.51cto.com/wyfs02/M00/8F/AC/ Wkiom1joacrjfpdfaaajijbnjei755.png-wh_500x0-wm_3-wmp_4-s_3074238118.png "alt=" Wkiom1joacrjfpdfaaajijbnjei755.png-wh_50 "/>
Print also prints integers, or calculates the results
--Practice: 100+200=300
650) this.width=650; "title=" 6.png "src=" https://s5.51cto.com/wyfs02/M00/8F/AA/ Wkiol1joammdzfpnaaaefzwyu8e499.png-wh_500x0-wm_3-wmp_4-s_3726919826.png "alt=" Wkiol1joammdzfpnaaaefzwyu8e499.png-wh_50 "/>
--Exercise: Print the string in two ways Hello World
650) this.width=650; "title=" 7.png "src=" https://s5.51cto.com/wyfs02/M02/8F/AC/ Wkiom1joaxhr8hqtaaahn3qc0me301.png-wh_500x0-wm_3-wmp_4-s_3881264023.png "alt=" Wkiom1joaxhr8hqtaaahn3qc0me301.png-wh_50 "/>
4.Python comments
Comments are used to illustrate the code, to yourself or to others to see
The Python interpreter ignores comments directly while the program is running
#开头, after which the code is counted as comments
5. Variables
What is a variable: literally means the amount that can be changed
Variables in the program in memory open up a space to store data place, and then a name, the name is the variable name.
Variables can store any data and must be assigned when declaring variables
Variable name: Can be arbitrarily taken, but to follow certain rules, must be the case of the English, numeric and underline combination, cannot start with a number
A=100 variable A is an integer
A= ' Hello ' variable A is a string
Variable characteristics: variable itself type is not fixed, Python dynamic voice, the advantages of more flexible
--Practice:
x=10;
x=x+2;
Print (x)//12
Print (x+2)//14
Print (x=x+2)//Error
Print (x==x+2)//false
650) this.width=650; "title=" 8.png "src=" https://s1.51cto.com/wyfs02/M01/8F/AC/ Wkiom1joa9fzn6wzaaase6glzxg669.png-wh_500x0-wm_3-wmp_4-s_607251180.png "alt=" Wkiom1joa9fzn6wzaaase6glzxg669.png-wh_50 "/>
--Practice:
A= ' ABC ';
B=a;
A= ' XYZ ';
Print (a); Xyz
Print (b); Abc
650) this.width=650; "title=" 9.png "src=" https://s1.51cto.com/wyfs02/M02/8F/AC/ Wkiom1jobinygfxzaaajkvl27ik191.png-wh_500x0-wm_3-wmp_4-s_2061174229.png "alt=" Wkiom1jobinygfxzaaajkvl27ik191.png-wh_50 "/>
Defining strings in Python
‘’ “”
What if the string itself has quotation marks? I ' m OK single-lead double-lead to wrap each other;
What if the string has both a single quote and double quotes?
Escape character \
Str= ' Kate said ' I ' m OK '
Demand output: Escape character Kate said "I ' m OK"
650) this.width=650; "title=" 10.png "src=" https://s4.51cto.com/wyfs02/M00/8F/AC/ Wkiom1jobf3jbzulaaaftdgac4e297.png-wh_500x0-wm_3-wmp_4-s_797346949.png "alt=" Wkiom1jobf3jbzulaaaftdgac4e297.png-wh_50 "/>
This article is from "Hello Sunshine" blog, please be sure to keep this source http://hexiaoshuai.blog.51cto.com/12156333/1914073
First: Getting Started with Python basics