60-minute Python quick learning (give your brother a confession)
Read Catalogue
- The first step: development environment Construction:
- The first Python feature: first knowledge of Python
- No data types are required for variables defined in 02.Python
- 03. Defining Methods in Pythod
- 04. Write your own class in Python
60-minute Python quick learning
Before and colleagues talked about Python, every time after work is listening to him, for example, Python is "glue language", belongs to "interpreted language!" "," is the object-oriented language! , there is no data type, the logic depends on the space indent representation and so on.
Today, it took me 60 minutes to learn the syntax of Python quickly. Share with you, but also be yourself this one-hour study summary it!
Back to top first step: development environment Construction:
Pycharm 4.5.4
: http://www.jetbrains.com/pycharm/download/
Support for multiple types of operating systems, I was installed on window 7 this time.
After downloading, the fool-type next can be.
Required plugins (engines integrated in Pycharm), which is Python
https://www.python.org/downloads/release/python-2710/
It is important to note that if you install the Pycharm development tool before you install Python, you will need to restart the Pycharm software and let him find the python you have installed as a project environment support. Don't worry, he can get it automatically.
Once you've created your project, you're ready to start.
First, a picture.
A file that corresponds to a Python syntax block
When a package is created under a project, a _init_.py is created by default (don't underestimate him, and you'll say how I got caught in the pit).
Back to top the first Python feature: first knowledge of Python
This case is mainly about two things:
How to support Chinese in a 01.PyCharm environment.
Operation Scheme:
Click the first item in the menu bar "File" → "Settings", then do the settings as
Note here that if the code set in the current project encoding is "UTF-8", it must be set to UTF-8 in our own project file, otherwise garbled. Of course, if you set the encoding in Project encoding to "gb2312", then the encoding in the project file has to be set to "gb2312"
Back to top of 02. Data types are not required for defining variables in Python
With a basic variable base, we can talk about branching in the next step. It's also a routine to learn any language,
Variable
Branching structure
Loop structure
Array
Method definition
Class definition
Inheritance and polymorphism
Import a package or namespace
So let's discuss the branching structure.
# coding=utf-8 __author__ = ' Happy ' score=90 if (score>=90): Print ("You're Awesome") elif (score>=80): Print ("excellent") elif (score& GT;=60): Print ("good")
Parse: Yes, there is no {} in Python, with: Represents a block of code, and then the statement ends without semicolons. Logic is fully represented by indentation
03. Cyclic structure
# coding=utf-8 __author__ = ' Happy ' for I in Range (0,3): print (i) Print ("End")
The syntax for the For loop is so, how do you differentiate "end" from being output only once?? can be indented. That's right. is indented again.
Back to top 03. Defining Methods in Pythod
#coding =utf-8 __author__ = ' Happy ' def SayHello (): Print ("Hello") # Call Method SayHello ()
Resolution: Just use Def as the prefix, and JS almost right! Oh! @
Then still pass: block of code as a method
The method call is called directly from the method name in the case of ok!, which shows the notation in Python in the form of # content.
Back to top 04. Write your own class in Python
#coding =utf-8 __author__ = ' Happy ' class Dog:def __init__ (self,name): Self.name=name def Eat (self): print ("hello,{0}". fo Rmat (Self.name)) F=dog ("Dou Dou") f.eat ()
Parse: Yes, define your own structure is def _init_ (self, parameter list), and then do not have to form a class member variable, you can use the. property, hehe is not very powerful. It is important to note that _init_ is not written as _int_ (the Blood Lesson), and then the object is created, not the new keyword. The direct construction is OK. Oh! @
Solutions for inheriting and importing external classes in 05.Python
# coding=utf-8 __author__ = ' Happy ' class Firsttest:def __init__ (self,name): Self.name=name print ("first,{0}". Format ( Self.name)) def FIRSTMM (self): print ("Parent Method") class Secondtest (firsttest): def __init__ (self,name): Firstt Est.__init__ (Self,name) def secondmm (self): print (Self.name) s=secondtest ("Happy") S.FIRSTMM () s.secondmm () #导入 The Goodteacher class from the teacher.py file is from Teacher import Goodteacher gt=goodteacher () GT. Eat ()
teacher.py file contents are as follows
# coding=utf-8 __author__ = ' Happy ' class Goodteacher:def __init__ (self,name): Self.name=name def Eat (self): print ("Eat s Omething ")
Parsing: Yes, inheritance only needs to be added to the second class definition (the parent class name), and then the parent class construct is OK in the method body of the subclass construct. and Java and C # almost Ah!
The method of importing an external class is the class name in the From file (not the suffix) import file
You can then use the members of the external class.
Oh!
Well, it's just a lesson.
In the end, it is also possible to configure Python's development environment in vs2013.
Here is a simple paste map as the finishing touches, but also for the elder brother has an explanation. I can say that my brother has a simple understanding of the rules of Python grammar.
Http://www.cnblogs.com/weilengdeyu/p/4821025.html
Python is a strongly typed language, and how can there be no type.
Spaces are indented to control blocks of code, just like {}, and control logic is not a concept.
60-minute Python quick learning (GO)