First, the development of Python
1. Development:
1) Advanced languages: Python, Java, PHP, C # Go Ruby C + + ===> bytecode
2) Low-level language: C, compilation
2, the comparison between the languages:
1) Python JAVA: Can write Web page, also can write background function
-python: Low execution efficiency and high development efficiency
-java: High execution efficiency and low development efficiency
2) PHP: Only for writing web pages
3) Python type:
Jpython
IronPython
Javascriptpython
Rubypython
CPython
4) Install: Python installed on the OS, do the following: Write a file in accordance with Python rules, the file to Python software, read the contents of the file, then convert and execute, and finally get the results.
Python3 is continuing to update
Python2 is continuing to update
Windows: Download python:www.python.org Select the latest version
#环境变量: Click on My Computer right-click Properties, select Advanced System Settings, and then edit path to add a new path to the installation of Python directly on the back.
3. Python Basics
1) The first sentence of Python:print ("Hello World")
When building a file:-the suffix name is self-willed?
--When the module is imported. Error if not with. py
Therefore, the file name suffix will be used. py
2) Interpreter path: #!/usr/bin/env python
3) Code: #-*-Coding:utf8-*-Python3 do not pay attention to Python2 must be added (2 the default is Ascill)
4. Perform an operation
Reminder user input: User and password
Get user name and password, detect: Username =root password =root
Correct: Login Successful
Error: Login failed
1Name ="Sun"2Password ="123123"3n = input ("Please enter user name")4m = input ("Please enter your password")5 ifname = = N andPassword = =m:6 Print("Welcome")7 Else :8 Print("Try again") 9
5. Variable name:-letter-number-underline
PS: numbers do not start
cannot be a keyword
It's best not to repeat the python built-in stuff.
6. Conditional statements
Indent with 4 spaces
A. First mode
N1 = input (' >>> ')
If "xiaoming" = = "Xiaoming":
N2 = input (' >>> ')
if N2 = = "Confirm":
Print (' XIAOMINGSB ')
Else
Print (' xiaomigndb ')
Else
Print (' ERROR ')
Attention:
N1 = "Alex" Assignment (an equal sign is a value assignment)
N1 = = ' Alex ' comparison, (two equals is a comparison)
The second form of B.if
If condition 1:
Passpass means empty code, meaningless, just to represent a block of code
Elif Condition 2:
Pass
Elif Condition 3:
Pass
Else
Pass
Print (' End ')
C. Conditions 1
And OR
if N1 = = "Xiaoming" or N2 = = "Xiaoming!23":
Print (' OK ')
Else
Print (' OK ')
7. Basic data types
string-N1 = "xiaoming" n2 = ' root ' n3 = ' "" "Eric" "" N4= "' Tony '
Number-age=21 weight = fight = 5
Subtraction, etc.:
String:
Addition:
N1 = "Xiaoming"
N2 = "SB"
N4 = "db"
N3 = n1 + n2 + N4
# "XIAOMINGSBDB"
Multiplication:
N1 = "Alex"
N3 = N1 * 10
Digital:
N1 = 9
N2 = 2
N3 = n1 + N2
N3 = N1-n2
N3 = N1 * N2
N3 = n1/n2
N3 = n1% N2
N3 = N1 * * N2
Question:
11 12 13 ...
num = 12
n = num% 2
if n = = 0:
Print (' even ')
Else
Print (' odd ')
9. Cyclic dead Loop
While 1==1:
Print (' OK ')
10. Exercises
1 # using while loop input 1 2 3 4 5 6 8 9 2 count = 13 while Count < one:4 if count = = 7 : C11>5 pass6 else:7 Print (count)8 count + = 1
#使用while循环输入1 2 3 4 5 6 8 9
1 # all numbers of the 1-100 are calculated and 2 i = 13 u = 04 while I <101 :5 u = U + i 6 i + = 17Print(u)
#求1-100 of all numbers of the and
1 # all odd numbers within the output 1-100 2 count = 03 while count < 101 :4 tmp = count% 25 if tmp = = 0:6 Pass 7 Else : 8 Print (count) 9 Count + = 1
#输出1-all odd numbers within 100
1 # all even numbers in the output 1-100 2 count = 03 while count < 101 :4 tmp = count% 25 if tmp = = 0:6 Print (count) 7 Else : 8 Pass 9 Count + = 1
#输出1-All even numbers within 100
1 #all the numbers of 1-2+3-4+5.....99 and2n = 13s = 0#S is the sum of all the previous numbers4 whileN < 100:5TEMP = n 26 iftemp = =0:7s = S-N8 Else:9s = s +NTenn = n + 1 One Print(s)
#求1 All the numbers of -2+3-4+5.....99 and
Python Foundation Day1