Character encoding
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Comments:
Single-line Comment: # Comment Content
Multi-line Comment: ' comment content '
Save and output the user input information
3.X
User_input = input ("Your Name:")
Print ("User name:", User_input)
2.X
User_input = Raw_input ("Your Name:")
Print ("User name:", User_input)
Formatted output:
#!/usr/bin/env python#-*-coding:utf-8-*-# author:hudengzhiname = input ("Your Name:") age = Int (input ("Your Age:")) job = Input ("Your job:") msg = ' Infomation of user%sname:%sage:%djob:%s '% (name, name, age, Job) print (msg)
Primary knowledge of common modules
#1. Ciphertext input
Import Getpass
Username = input ("")
Password = getpass.getpass ("Password:")
Print (Username,password)
#2. OS module use
Import OS
Os.system ("DF")
Os.mkdir ("Yourdir")
Os.system ("LS")
Cmd_res = Os.popen ("Df-h"). Read ()
Print (Cmd_res)
#3. Module Storage Path
Import Sys
Print ("Sys.path")
/usr/lib/python2.7/dist-packages # #自己写的模块一般放在此目录
#4. If statement
#!/usr/bin/env python
#-*-Coding:utf-8-*-
# Author:hudengzhi
user ="Hudengzhi"
passwd ="123456"
username =input("Username:")
Password =input("Password:")
ifUsername = = User:
Print("username is correct ...")
ifPassword = = passwd:
Print("Welcome login ...")
Else:
Print("Password is invalid ...")
Else:
Print("Even the user name is not written right, get out!" ")
#5 for Loop
Age = 22for I in range: guess_num = Int (input (' Age: ')) if guess_num = = Age:print ("Congratulations, you got it") bre AK #不再往后走, jump out of the entire loopelif guess_num > Age:print ("Think smaller") else:print ("Think big")
This article is from the Python Basic Learning Notes blog, so be sure to keep this source http://hudengzhi.blog.51cto.com/1319933/1859045
Python Basics Learning Notes