Description
1. Python Installation
Choose Windows installation, version 3.5.2 2.x version and 3.x version difference is large, the old version does not support the new features
: https://www.python.org/downloads/windows/
Unzip to run when download is complete
Direct Output content:
Print ("Hello Word")
You can write a script and then execute:
c:\users\admin>c:\users\admin\desktop\hello.py
Print ("Hello Word")
Install under Linux, add permissions when executing:
#!/usr/bin/env python env means looking for python under the global path
or use an absolute path
#!/usr/bin/python If you use a high version you can't write dead
2. Python Common programming tools
pycharm-professional-2017.1.4 can be configured inside the template
3, Variable Description:
Declaring variables and getting variables
Name = "Caicai"
Name1 = "Zhenzhen"
Name = "Caicaiaizz"
Print (NAME,NAME1)
Below the overlay above, get to the variable record into memory
4, character encoding problem: Support Chinese need to bring the Utf-8 character set
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Print "Hello, World"
5. Comments
Single-line comment: Using #
Multiline Comment: Use "'" ' 3 quotation marks to start 3 quotes end, single or double quotation marks can be
Multi-line Comment 2 Purpose: comments and Multiline assignment
Msg= ""
Name = "Caicaiaizz"
Print "Hello, World"
‘‘‘
Print (msg)
6. User interaction Input (Note Python version issue)
Using Read-p in the shell
Using input in Python
# _*_coding:utf-8_*_
Username = input ("Username:")
Password = input ("Password:")
Print (Username,password)
-----------------------------------
-----------------------------------
Concatenation of strings: it consumes a lot of memory, it is not recommended
Method One: Use the form of placeholders (common methods)
#From Caichao
Name = input ("Name:")
age = Int (input ("Age:"))
Print (Type (age))
Job = input ("Job:")
info = ""
---------Info of%s--------
name:%s
age:%d
job:%s
"% (Name,name,age,job)
Print (info)
Method Two: Use format for values (used in specific situations)
#From Caichao
Name = input ("Name:")
age = Int (input ("Age:"))
Job = input ("Job:")
info = ""
---------info of {Name}--------
Name:{name}
Age:{age}
Job:{job}
". Format (Name=name,age=age,job=job)
Print (info)
Note:
1), print out the string type of a variable: print (type (age))
2),%s stands for placeholder, starting from 1, and so on
3),%d delegates must use integers for input
4),%f for floating-point string, can enter decimal
5), Fromat the introduction of variables can be
-----------------------------------
7, password in the form of ciphertext input
#From Caichao
# _*_coding:utf-8_*_
Import Getpass
Username = input ("Username:")
Password = getpass.getpass ("Password:")
Print (Username,password)
8, if logic judgment, the user name and password to determine the equal permission to login
#From Caichao
# _*_coding:utf-8_*_
Import Getpass
UserName = "Caicai"
Password = "123"
Username = input ("Username:")
Password = input ("Password:")
if UserName = = UserName and Password = = Password:
Print ("Welcome user {name} login". Format (Name=username))
Else
Print ("Error,please checkout!")
9, multiple if judgment, guess age
#From Caichao
Age_of_oldboy = "56"
Guess_age = input ("Guess Age:")
if guess_age = = Age_of_oldboy:
Print ("Yes!you is Rige")
Elif Guess_age < age_of_oldboy:
Print ("Think smaller!")
Else
Print ("Think bigger")
This article from "Liu" blog, declined reprint!
Learn python-01 with me.