The first day of python O & M development and the first day of python Development

Source: Internet
Author: User

The first day of python O & M development and the first day of python Development

I. python installation and environment variable configuration

1. Install python in Windows 7

1): https://www.python.org/downloads/windows/

For example:

Note: It will be much better to use a proxy for download.

2) install python3.6

After you double-click it, remember to add python to Path to add the Python installation Path to the Path variable of the system environment variable. Then select the custom path. The default C disk is also supported.

Next step: select all by default

Next step: Check the first option, Install for all users, and select your own directory.

 

The installation process is still relatively fast. Just wait a moment.

After installation, open the cmd on the computer and verify whether the installation is successful. Check whether the environment variables are set. Enter python in cmd and press Enter, if python version is displayed, the software is installed.

If the verification in the previous step fails, it may be that the environment variable is not set. Enter set Path in the command line to open the Path variable of the system environment variable and check whether there is a Python directory (for example)

If not, you can only manually add (reference: http://www.cnblogs.com/willpower-chen/p/5555682.html)

 

 

2. Install python in linux. Here I use ubuntu and use pyenv to manage and install python.

Pyenv is a tool for managing Python versions. It supports switching between multiple Python versions.

1) download pyenv

Git clone https://github.com/yyuu/pyenv.git ~ /. Pyenv

2) SetPYENV_ROOTAndpyenv initAdd bash ~ /. Bashrc (or zsh ~ /. Zshrc)

Root @ drone-test2:/home/ubuntu # echo 'export PATH = ~ /. Pyenv/bin: $ PATH '> ~ /. Bashrc
Root @ drone-test2:/home/ubuntu # echo 'export PYENV_ROOT = ~ /. Pyenv '> ~ /. Bashrc
Root @ drone-test2:/home/ubuntu # echo 'eval "$ (pyenv init-)" '> ~ /. Bashrc


3) Restart shell: Restart your shell so the path changes take effect. You can now begin using pyenv.

 

4) install the specified version of python

Before installing python, you need to install some dependent packages and libraries:

You can also choose to install:

 

View the python installable version and install the specified version

By default, python 2.7.6 of ubuntu is started.

After installation:

  • Source Code (for example ~ /Python-3.6.0a3.tar.xz) is cached in the. pyenv/cache directory and can be manually deleted after installation.
  • Python version installed in ~ /. Pyenv/versions directory.

Use pyenv to modify the default python version.

You can also use export to modify it. Its variable name is PYENV_VERSION.

For more pyenv learning, refer:

 

 

 

Ii. install and configure pycharm

1. installation:

2. pycharm configuration and shortcut keys

Reference: http://www.cnblogs.com/willpower-chen/p/5612493.html

Http://www.cnblogs.com/willpower-chen/p/5556619.html

Http://www.cnblogs.com/willpower-chen/p/5556508.html

You need to add:

Display Settings of setting in the toolbar

 

Iii. python Basics

1. Write Hello world

1) execute the output directly through the interpreter

2) Compile pycharm

The file created here will automatically add the suffix. py to tell us this is a python-related file.

 

In addition, the created file is executed in python in the dos window.

 

2. Variables

1) What is a variable?

A variable is a box that contains various things. Apple is installed. When the box works with other things, it is an apple. When it is installed with a Yali, it is also a Yali when it cooperates with other things.
The variables in the compiled language require that the box be fixed. If the box is loaded with fruit, the box is loaded with fruit, and the box is loaded with noodles.
Variables in interpreted languages are not required. When it works with a fruit, it uses it as a fruit; when it works with a face, it uses it as a face.
A variable in the broad sense is relative to a constant, which refers to the variable quantity. Variables are absolute, constants are relative, and there is no absolute constant. B. A variable is a sequential storage space with a name. We apply for and name such a bucket by defining variables, and use the bucket by the variable name.
A variable is a place where data is temporarily stored in a program. It can store words, values, dates, and attributes. 2) Definition rules of variables:

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

B. the first character of the variable name cannot be a number.

C. The following keywords cannot be declared as variable names
['And', 'as', 'assert ', 'Break', 'class', 'contine', 'def', 'del ', 'elif ', 'else', 'Got t', 'exec ', 'Finally', 'for ', 'from', 'global', 'if', 'import', 'in ', 'Is ', 'lambda', 'not ',' or ', 'pass', 'print', 'raise ', 'Return', 'try', 'while ', 'with', 'yield ']

3) variable assignment: a. Replace name1 with "zhangsan" between variables"

Name2 = name1

Name2 points to --> name1's memory space address "zhangsan"

So what name2 actually points to is: memory space address "zhangsan"

Name1 = "lisi"

Only changed the address of the memory space pointed to by name1 -- "lisi"

Here name1 has changed, and name2 has not changed

B. Verification: for example

Result:

 

3. Input and Output

Execute Interaction:

To hide the entered password, use the getpass method in the getpass module, that is:

Note: Because pycharm does not support the getpass module, the following verification is performed in windows dos:

 

 4. Process Control and indentation

The python syntax uses a strict indent method, and the same level must

1) Requirement: user login verification

#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-
# @ Time:
# @ Author: Willpower-chen

# Enter the user name and password
# Verify the user name and password
# If a verification error occurs, the system prompts that the user name or password is incorrect.
# If the verification is correct, a prompt is displayed!

# Import the getpass Module
Import getpass

Name = input ("Enter the User name :")
Passwd = getpass. getpass ("enter the password :")

If name = "ligang" and passwd = "123456 ":
Print ("welcome", name)
Else:
Print ("the user name or password you entered is incorrect ")

Verification:

 

5. while Loop

1) Basic cycle

 

2) break

Break is used to exit the while LOOP body.

While True:
Print ("")
Break
Print ("B ")
When "a" is printed, the entire cycle will jump out of the break, "B" will not be printed, and "a" will not be printed cyclically"

3) continue

'''
Continue is used to exit this loop and continue the next loop
'''
While True:
Print ("")
Continue
Print ("B ")

When "a" is printed, it will jump out of the loop that prints "B" and continue the next loop, that is, this will happen each time, so "a" is printed continuously"


 

 



 

 

 

Related Article

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.