Configuration environment variable
- Purpose: decrease in the input path cmd, so that the operation convenient
python suffix: .py
Two execution methods:
- cmd terminal input path: Python interpreter, py file path;
- Entering the python interpreter, real-time input to obtain the results.
Interpreter path and encoded using
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
User and password input operation
n1 = input ( 'Enter a username')
N2 = INPUT ( 'Enter Password')
Print (N1)
Print (N2)
a1 = input ( 'username')
IF A1 == 'ZX':
A2 = INPUT ( 'password')
IF A2 == '123':
Print ( 'Welcome')
the else:
Print ( 'error code')
the else :
Print ( 'username error')
variable name
- Only by letters, numbers, underscores composition dd_2) 55d
- You can not start with a number, 88_ass
- Python keywords can not be used (and, AS, Assert, BREAK, class, Continue, DEF, del, elif ...) class = 123
- Can not be repeated and built something python
Variable naming is an art userid userID user_id
Conditional statements
- Code block: 4 space indentation / Tab key
1 == 1 IF: Print ( "Success") the else: Print ( 'failure')
IF . 1. 1 == : IF 2 == 2 : Print ( ' success ' ) the else : Print ( ' failure ' ) the else : Print ( ' failure ' )
inp = input ( 'Enter level') IF InP == "senior member": Print ( 'beauty') elif InP == "Platinum Member": Print ( 'polish') elif InP == "Platinum Membership": Print ( 'member') Print ( 'begin service')
a = 1 if a < 9: pass else: print(a)