gh_02_01_Python first acquaintance

---Restore content begins---

content:

There are two ways to open the Python software:

Configure the path environment variable under Windows:

perform an action

Variable definitions:

if statement:

 

There are two ways to open the Python software :

1. Double-click the software name to open

2. Enter the command on the terminal to open, python D:\filename.py This method can directly open the software plus the file

 

Configure the path environment variable under Windows :

Open My Computer Properties - Advanced System Settings - Advanced - Environment Variables - Find Path View Path - Add Python2.7 or Python3.6 Path

# coding=utf8 \\You can use as much as you can express

Perform an operation
Remind the user to enter: user and password
Obtain the user name and password, check: user name=root password=root
Correct: Login successful
Error: Login failed

# The usage of input, wait forever, until the user enters a value, it will assign the input value to a variable 
user = input( " Please enter the user name: " )
password = input( " Please enter the password: " )
 if user == " root "  and password == " root " :
     print ( " Login successful " )
 else :
     print ( " Login failed, please try again! " )

Variable definitions:

It can only consist of letters, numbers, and underscores . It cannot start with numbers, and it cannot use keywords as variables. Don't duplicate what's built into Python.

keywords 

and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'等等

if statement:

①if basic statement

if condition to be judged:
    conditions are met, things are executed
    ……
else:
    The condition is not established, the thing to be executed
    ……

 

② Use of if elif

If condition to be judged ①:
    Condition ① is established, the thing to be executed
    ……
Conditions to be judged by elif ②:
    Condition ② is established, the thing to be executed
    ……
Conditions to be judged by elif ③:
    Condition ③ is established, things to be executed
    ……
else
    What to do when none of the above conditions are met
    ……

③ Nested usage of if

If   condition to be judged ①:
      Condition ① is established, the thing to be executed
       ……
    The basis of if condition ①, the condition of judgment ②:
         Condition ② is established, the thing to be executed
         ……
   else
        Condition ② is not established, things to be executed
         ……
else
     Condition ① is not satisfied, the thing to be executed
     ……

   Supplement ": if the condition is met, do not want to execute with pass

 

 

 

 

---End of recovery content---

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325891487&siteId=291194637