Python Finishing-day1

Source: Internet
Author: User

Python installation

1. Download the installation package     HTTPS://WWW.PYTHON.ORG/DOWNLOADS/2, install the     default installation path: C:\python27 3, configure     the environment variable "right-click Computer"-"Properties"-"Advanced system Settings" --"Advanced"-"Environment variable"-"in the Second content box find a row of the variable named path, double-click the"-"Python installation directory appended to the variable value, use; split"     such as: the original value; C:\python27, remember that there is a semicolon in front of 4, installed on the machine pycharm, through Pycharm to write code, Pycharm can choose the appropriate Python version number

Interpreter

#!/usr/bin/env python#-*-coding:utf-8-*-# AUTHOR:WZC

Env is used here, and when you specify the interpreter in Python, you must use ENV instead of writing the absolute path directly.

This usage is intended to prevent operating system users from not loading Python into the default/usr/bin path. When the system sees this line, it will first find the Python installation path in the env settings, and then call the interpreter program under the corresponding path to complete the operation.

In the script

-*-Coding:utf-8-*-mainly because in the python2.x version, the Chinese encoding does not work properly, so need to add this sentence, and in python3.x this has been resolved

Variable

#!/usr/bin/env pythonname= "WZC"

The name here is the variable, and I assign the WZC to the name variable.

Variable names can only be any combination of letters, numbers, or underscores

The first character of a variable name cannot be a number

The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

Comments

When the line stares: # is annotated content

Multiline Comment: "" "Annotated Content" ""

#user =ww ' passwd= ' wwzzcc '

Input

#!/usr/bin/env python#-*-coding:utf-8-*-# author:wzcimport getpassuser= ' wzc ' passwd= ' wwzzcc ' user_name = input (" Please input your name: ") Password = getpass.getpass (" Please input you password: ") if user = = user_name and passwd = = Passwor D:    print ("Welcome login ...") Else:    print ("To die ...")

It's important to note that since I'm using the python3.x version in the development, I have input only (), and python2.x has Raw_input ()

However, it is important to note that this input is shown in clear text, if you do not want to let the user's input be realistic, you can use Getpass this module

Module

There are many modules in Python with powerful third-party libraries

Tab completion module for Mac version

Import Sysimport readlineimport Rlcompleterif sys.platform = = ' Darwin ' and sys.version_info[0] = = 2:    readline.parse_ And_bind ("Bind ^i Rl_complete") Else:    readline.parse_and_bind ("Tab:complete")  # Linux and Python3 on Macfor mac

The tab completion module of the Linux version

#!/usr/bin/env Python # python startup file import sysimport readlineimport rlcompleterimport atexitimport os# tab complet Ion Readline.parse_and_bind (' Tab:complete ') # history file Histfile = Os.path.join (os.environ[' HOME '), '. pythonhistory ') Try:    readline.read_history_file (histfile) except IOError:    passatexit.register (Readline.write_history_ File, histfile) del os, Histfile, ReadLine, Rlcompleterfor Linux

Expressions If...else and expressions for

#!/usr/bin/env python#-*-coding:utf-8-*-# author:wzcnum=22count=0for i in range:    if count < 3:        Guess_nu m = Int (input ("Input you num:"))        if num = = Guess_num:            print ("ok!")            Break        elif Num < guess_num:            print ("Think smaller")        else:            print ("Think Big")        count + = 1    else:        aa=input ("Do-want, go on?")        if aa = = ' Yes ':            count=0        Else:            print ("Bye")            break

This is done through a for loop, which is judged by the IF. So that the entire program runs

Here we need to introduce

Break and Continue

Break

For W in range:    if w = = 5: Break     Print W

The break in this is jumping out of the entire for loop, and the w=5 behind is not executed.

Continue

For W in range:    if w = = 5:        continue     print (W)

This inside continue just jumps out of the current layer of the loop, that is, only 5 this layer does not show

Python Finishing-day1

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.