1. User input
#!/usr/bin/env python#_*_coding:utf-8_*_#name = Raw_input ("What's your Name?") #only on Python 2.xname = input ("What is Y Our name? ") Print ("Hello" + name)
2, enter the password, if you want to be invisible, you need to use the Getpass method in the Getpass module, namely:
#!/usr/bin/env python#-*-coding:utf-8-*-import getpass# assigns the user input to the name variable pwd = getpass.getpass ("Please enter password:") # Print the contents of the input PRI NT (PWD)
3. SYS module
#!/usr/bin/env python#-*-coding:utf-8-*-import sysprint (SYS.ARGV)
#输出
$ python test.py helo world[' test.py ', ' helo ', ' World ' #把执行脚本时传递的参数获取到了
4. OS Module
#!/usr/bin/env python#-*-coding:utf-8-*-import osos.system ("Df-h") #调用系统命令
Import Os,sysos.system (". Join (sys.argv[1:])") #把用户的输入的参数当作一条命令交给os. System to perform
5. If statement
Scenario One, user login verification # Prompt for user name and password # verify username and password # if error, output username or password error # If successful, then output welcome, xxx! #!/usr/bin/env python#-*-coding:utf-8-*-import getpassname = raw_input (' Please enter user name: ') pwd = Getpass.getpass (' Please enter password: ') if NA me = "Alex" and pwd = = "cmd": Print ("Welcome, alex! ") else:print (" User name and password error ")
6. Expression for loop
The simplest loop 10 times
#!/usr/bin/env python#_*_coding:utf-8_*___author__ = ' Alex Li ' for I in range: Print ("loop:", i)
7. While loop
Count = 0while True:print ("You are the wind I am the sand, tangled up to the horizon ...", count) Count +=1
This article is from the "Corasql" blog, make sure to keep this source http://corasql.blog.51cto.com/5908329/1910373
Python Learning Notes Introduction, basic grammar, Process Control