- Memory address query for Python variables
# !/usr/bin/env python # -*-coding:utf-8-*- " Zhang " "Frank"ID (name)
- Process Control and Indentation
- Syntax for Process Control
If condition:
Executes the next statement (content)
Content 2
Else
Content 3
Content 4
Python language indentation must be the same, or with 4 spaces, it is generally strongly recommended to use four spaces instead of Indentation. Because it can be used in different system Environments. There is no problem with program incompatibility due to indentation problems.
The difference between = and = = is an equal value of two equals is a comparison
#!/usr/bin/env python#-*-coding:utf-8-*-#The following procedure is to determinename1 = Raw_input ("Please enter the first user name") name2= Raw_input ("Please enter a second user name")ifName1 = =name2:Print("congratulations on your writing.") Print("you're not Stupid.--good by")Else: Print("Please re-enter")
Simple User name Password login program
#!/usr/bin/env python#-*-coding:utf-8-*-#The following procedure is to determineName = Raw_input ("Please enter user name") PWD= Raw_input ("Please enter your password")ifName = ="Zhangkun" andPWD = ="123": # If name = = "zhangkun" or pwd = = "123":
Print("Congratulations on your successful login") Print("you're not Stupid.--good by")Else: Print("Logon Failure")
Multiple Judgment syntax
If condition 1:
Elif condition 2:
....
Elif condition 3:
23444444
Else
Ssssss
The conditions are multiple and varied can be false, True, <,>,<>, = =, a==b and b==c, a = B or v = w, a! = b
#!/usr/bin/env python#-*-coding:utf-8-*-Name = Raw_input ("plase input a name:")ifName = ="Zhangk": Print("Good")elifName = ="Frank": Print("NO!!!, name is a 中文版 name")elifName = ="Yes": Print("you input yes isn't OK")elifName = ="No": Print("input No is not OK too!!!!!!!!!")Else: Print("you name does konw? is a SB")
- The While Loop statement uses the
While Condition:
......
The loop body is introduced after the condition is met. If the condition is not satisfied, it is called the cycle of Death.
code block
#!/usr/bin/env python#-*-coding:utf-8-*-A = Raw_input ("plase input a num:") b= 1ifA = ="3": whileb < 10: PrintStr"It's Circulating.")+a B= B+1Else: Print("He's a bloody Dead Man.")
When the loop body executes, How do you let the program execute once in a second? a time module is used here
#!/usr/bin/env python#-*-coding:utf-8-*-Importtime a= Raw_input ("plase input a num:") b= 1ifA = ="3": whileb < 10: PrintStr"It's Circulating.")+a time.sleep ( 1 ) b= B+1Else: Print("He's MD S.")
Python Study the next day