Deep understanding of python introduction, basic syntax, and process control

Source: Internet
Author: User
This article provides a detailed introduction to python, basic syntax, and process control. For more information, see section 1. user input.

#!/usr/bin/env python#_*_coding:utf-8_*_#name = raw_input("What is your name?") #only on python 2.xname = input("What is your name?")print("Hello " + name )

2. when entering the password, if you want to be invisible, you need to use the getpass method in the getpass module, that is:

#! /Usr/bin/env python #-*-coding: UTF-8-*-import getpass # assign the user input content to the name variable pwd = getpass. getpass ("Enter password:") # print the entered content print (pwd)

3. sys module

#!/usr/bin/env python# -*- coding: utf-8 -*- import sysprint(sys.argv)

# Output

$ Python test. py helo world ['test. py', 'helo', 'World'] # obtain the parameters passed during script execution.

4. OS module

#! /Usr/bin/env python #-*-coding: UTF-8-*-import osos. system ("df-h") # Call system commands
Import OS, sysos. system (''. join (sys. argv [1:]) # run the user input parameters as a command to OS. system for execution.

5. if statement

Scenario 1: User login verification # prompt for entering the user name and password # verify the user name and password # if an error occurs, the output user name or password is incorrect # if successful, the output is welcome, XXX! #! /Usr/bin/env python #-*-coding: UTF-8-*-import getpassname = raw_input ('Enter your username: ') pwd = getpass. getpass ('Enter password: ') if name = "alex" and pwd = "cmd": print ("Welcome, alex! ") Else: print (" incorrect user name and password ")

6. expression for loop

The simplest loop is 10 times

#!/usr/bin/env python#_*_coding:utf-8_*___author__ = 'Alex Li'for i in range(10):    print("loop:", i )

7. while loop

Count = 0 while True: print ("You are wind, I am sand, entangled in the world...", count) count + = 1

The above is a detailed introduction to python, basic syntax, and process control. For more information, see other related articles in the first PHP community!

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.