Python Basics Learning Notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.