"Testimonials: First thanks to Alex Teacher's wonderful course, the first day of the first week, with the Golden Horn King's heroic Heart Chicken soup perfect ending." Sitting in front of the computer at the moment I still blood surging, determined to follow the king to learn python well
----Wish teacher teachers ' Day Happy 650) this.width=650; "src=" Http://img.baidu.com/hi/face/i_f01.gif "alt= "I_f01.gif"/> Python first week
Blog structure:
The main difference between--1--python2.* and python3.*
--2--python Installation and Configuration
Installation and configuration of--3--pycharm development tools
Definition of--4--variable
--5--Use of annotations
--6--user input with formatted string
--7--Common Modules
--8--conditional Statements and loop statements
--9--Conclusion
The main difference between--1--python2.* and python3.*
ⅠPrint
The print in python2.* is used in this way:
print "Hello World"
This is the case in python3.*:
Print ("Hello World")
Ⅱ character encoding
The default character encoding in python2.* is ASCII, does not support Chinese, if you want to support Chinese encoding, you need to add the first line in the. py file ↓
#-*-coding:utf-8-*-
python3.* default is Unicode-enabled encoding.
Ⅲ Library name Difference (slightly)
Baidu Search by itself.
Summary: Above is the difference between python2.* and 3.*, of course python3.* interpreter is on the basis of 2 to do the optimization, this does not affect our programmers to apply Python, understanding is enough.
--2--python Installation and Configuration
Ⅰ : http://www.python.org/downloads/
Course needs: Download python2.7.11 and python3.5
Ⅱ Installing the default path
Python2.7:c:\python27
Python3.5:c:\users\administrator\appdata\local\programs\python\python35 (This is my default path, you may be different, it is best to write him down when installing, Subsequent setting of the environment variable will be used)
Ⅲ Setting Environment variables
My Computer ( right mouse button) Properties-"Advanced settings-" Environment variables-"Edit the second content box path, the top of the way to add to the back, note that" the path must have a semicolon "-" OK. " Basic setup, restart CMD for inspection. Enter Python, which proves successful if you enter the Python command-line mode.
Installation and configuration of--3--pycharm development tools
ⅰ: http://www.jetbrains.com/pycharm/Download the latest version, I'm under 2016.2
Ⅱ installation , the default installation path can be.
ⅲsetting Configuration (introduction three points) file-"setting
1, the Appearance basic property is set in the Appearance&behavior.
2. If you want to create a code template yourself, in Editor, file and code templates.
3. If you want to change the interpreter for the project: change in interpreter under Project.
Definition of--4--variable
Ⅰ the name of the variable
In short, none of the keywords can be defined as variable names.
The common way to write variable names is to use the following:
1, user_name
2, UserName
The point problem of Ⅱ variable
Name = "LCY" name2 = Nameprint (name, name2) #输出lcy, lcyname = "Alex" Print (name,name2) #输出Alex, LCY
Explanation: Name is the first time the string "LCY" assignment, pointing to the string address space, name and LCY in the space assigned to name2, so name2 also pointed to the "LCY" this space. Therefore the first output is LCY;
The second name is re-assigned a space that is assigned, while Name2 still points to the LCY space. Thus the name2 result has not changed.
--5--Use of annotations
Ⅰ the comment for the current line with "#"
#我是注释.
Ⅱ Comment Multiple lines (Note the bottom single quotation mark, the input method English half angle)
"I am a comment I am a comment I am a comment"
--6--user input with formatted string
User input:
ⅰpython3.* version:
User_input = input ("Please input your name:") ' The Accept user input data by default is considered to be a string type, that is, the strings. If you want to enter a digital integer, type conversion is required. " user_age = Int (input ("Your Age:")) #user_age is an integer value
ⅱpython2.* version:
User_input = raw_input ("Please input your name:")
Format string:
user_name = "LCY" user_age = 23user_money = 1000.0msg = "' myname:%s myage:%d mymoney:%f '"% (user_name, user_age, User_mon EY) Print (msg)
| format |
Description |
| %% |
Percent Sign |
| %c |
Characters and their ASCII code |
| %s |
String |
| %d |
Signed integer (decimal) |
| %u |
unsigned integer (decimal) |
| %o |
unsigned integer (octal) |
| %x |
unsigned integer (hexadecimal) |
| %x |
unsigned integer (16 uppercase characters) |
| %e |
Floating-point numbers (scientific notation) |
| %E |
Floating-point numbers (scientific notation, E instead of e) |
| %f |
Floating point number (with decimal point symbol) |
| %g |
Floating-point numbers (%e or%f depending on the size of the value) |
| %G |
Floating-point numbers (similar to%g) |
| %p |
Pointer (memory address of the value printed in hexadecimal) |
| %n |
Stores the number of output characters into the next variable in the parameter list |
--7--Common Modules
Ⅰgetpass (only works in 2.* version)
Import Getpass#import module name-directed into module passwd = Getpass.getpass () print (passwd)
Ⅱos Module
#运行指令import Osos.system ("Ls-l") #Linux下长显示当前目录os. mkdir ("LCY") #在当前目录下创建目录名为lcy # Read Results cmd_res = Os.popen ("Ls-l"). Read ( ) Print (Cmd_res)
Ⅲsys Module
Import Syssys.path # Returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing
The above several modules did not go into deep study, only did a brief introduction. Follow along with the course progress, will continue to update the module explained.
Import
This keyword is directed into the modules you need in the coding process. Generally, if the module name is duplicated, the current path is typically imported under the module.
Custom module or third-party module storage path:/usr/lib/python2.7/dist-packages (Linux); can be viewed via print (Sys.path)
--8--conditional Statements and loop statements
ⅠIf...else/if...elif...else
#判断条件成立否first_name = "LCY" Second_name = "Alex" user_name = input ("user_name:") if user_name = = First_name:print ("I am LC Y ") #缩进四个空格elif user_name = = Second_name:print (" I Am Alex ") Else:print (" Who? ")
Note: The execution statement under the conditional statement is indented four spaces. (Four standard)
Ⅱ Loop statement for
#i为循环计数器 range (n) cycles for I in range #循环打印十次hello, and I count from 0. Print ("Hello")
--9--Conclusion
The above is what I have learned today, there are shortcomings, but also ask you to criticize.
This article is from the "great God is not beyond the" blog, please be sure to keep this source http://wuyuzegang.blog.51cto.com/8653728/1851419
Python First week basics