First, Python introduction:
Python is an object-oriented, interpreted computer programming language, invented by Dutchman Guido van Rossum in 1989, and the first public release was released in 1991.
Python syntax is simple and clear, and one of the features is to force whitespace (white space) to be indented as a statement.
One, kind:
Jpython
IronPython
Javascriptpython
Rubypython
CPython **********
PyPy This is Python developed with CPython.
Ii. Basics of Python
2.1: The first knowledge of Python
- The file suffix name can be arbitrary, and when imported by Pycharm, the suffix must be. py
- The first sentence: print ("Hello World")
2.2: Two modes of execution
- Via terminal: Python interpreter py file path
- Enters the Python interpreter, enters and executes the get results display at all times.
2.3 Interpreter Composition
- #!/usr/bin/env python: Interpreter path
- #-*-Coding:utf8-*-encoding: Optimized for universal code, providing support for global character recognition. Python3: No special instructions required. python2l each file will appear in Chinese must be accompanied by a header file.
2.4 Executing the Action file
Reminder user input: User and password
Get user name and password, detect: Username =root password =root
Correct: Login Successful
Error: Login failed
A. Use of input, wait forever until the user has entered a value, will assign the value of the input to a thing
Name=input ("Please enter user name:") PSW=input ("Please enter your password:"ifName = ="Root" andPSW = ="123": Print("Landing Success")Else: Print("Login Failed")
2.5 Variable name rule
Composition: Letters, numbers, underscores.
Ps:① numbers can not start, ② cannot be the key words. ③, better not be python built-in stuff
2.6 Article statements
Indent 4 Spaces:
A:
N1 = input (' >>> ') if "alex" = "Alex": n2 = input (' >>> ') if N2 = = "Confirm":p rint (' Alex SB ') Else:print (' Alex DB ') Else:print (' ERROR ') Note: N1 = "Alex" Assignment n1 = = ' Alex ' comparison,
B:
if condition 1: Pass elif Condition 2: Pass elif Condition 3: Pass Else : Pass Print ('end')
C:
and orif N1 = = "Alex" or N2 = = "Alex!23":p rint (' OK ') else:print (' OK ')
2.7 Basic data types
String - n1 = "Alex" n2 = ' root ' n3 = "" "Eric" "" n4= "Tony" number - age=21 weight = 64 fight = 5 Subtraction: string: addition: N1 = "Alex" n2 = "SB" N4 = "db" n3 = n1 + n2 + n4# "alexsbdb" multiplication: N1 = "Alex" n3 = n1 * 10 Numbers: N1 = 9N2 = 2n3 = n1 + n2n3 = N1-N2N3 = N1 * N2n3 = N1/N2N3 = N1% N2N3 = N1 * * N2 quiz: ... num = 12n = Nu M% 2if n = = 0:print (' even ') else:print (' odd ')
2.8 Cycles
Dead loop
While 1==1:
Print (' OK ')
2.9 Exercises
1. Use while loop input 1 2 3 4 5 6 8 9 10
n = 1 while N < one: if n = =7 :pass else : print(n) = n + 1 print('----End---- ')
2. For all numbers of 1-100
n = 1 = 0 while n < 101: = s + n = n + 1 print (s)
3. All odd numbers in output 1-100
n = 1 while N < 101: = n 2 if temp = = 0: pass else: print(n) = n + 1 print('-- --end----')
4. All even numbers in output 1-100
n = 1 while N < 101: = n 2 if temp = = 0: print(n)
Else: pass = n + 1 print(' ----End----')
5, Beg 1-2+3-4+5 ... 99 of all numbers of the and
n = 1 # S is the sum of all previous numbers while n <: = n% 2 if temp = = 0 := s - nelse := s + n= n + 1 Print (s)
6, User login (three chance to retry) "Write Yourself"
#!/usr/bin/env pythonN=1 whileN<4: Name= Input ("Please enter user name:") PSW= Input ("Please enter your password:") ifName = ="Root" andPSW = ="123": Print("Landing Success") Break Else: Print("Login failed, please re-enter") n=n+1Else: Print("failed more than three times, please retry after 30 minutes!:")
Python Learning-day01