First of all
Introduced
Python It is a high-level programming language that has its own data structure to reduce the time it takes to build a "frame" in the previous programming. The list in Python (a variable-sized array), a dictionary (hash table), is built into the system itself. Python is an object-oriented language, and its extensibility and portability are very good.
Official website: https://www.python.org/
Learn to prepare VS2013, Python, PTVS2013.
1. Open vs2013, double-click
2. Download Python tools for Visual Studio and install
This time, you can already start knocking on the code, the first sentence.
Print ("helloworld"
F5
Missing things, the original is you wood has installed Python, it seems to only download a tools, or not enough, come on, download installation
Next, next ....
After the installation, the next step, F5
-----------------------------------------------Start Learning----------------------------------------------------------------
Variables and types
Variables are automatically recognized without int what string what, type declaration
The name of the variable can not be random, it can be composed of characters, numbers, underscores . However, it cannot start with a number, nor can it use spaces inside it.
Octal: Starting with 0 num=017
Hex: Start with 0x num=0x92
Long integer type
Long integers in Python are different from long integers in other compiled languages, and do not require a range of 32-bit or 64-bit.
The long length of Python is related to the size of the (virtual) memory your machine supports. In other words, as long as the content is sufficient, it can represent a very large number of values.
When we express a long integer, we'd better add a capital "L" to the back of the number.
I don't know why I got an error in vs 2013.
Output
String
' It is a sample ' "It is a sample"
Both of these methods are OK, like JS, with "and" "
If there are quotation marks in the string quotation marks, you can do this:
" it ' s a sample " 'it\ ' A sample'
1: Double quotation mark nested single quote 2: use \ Escape character
Branch string:
When a string requires multiple lines of representation, you can use the "' or" "(someone uses a multiline comment?). )
String variable subscript
To take a character in a string, or a segment of a character, based on a string subscript
Array List
In Python, they exist in the form of lists (list) and tuples (tuple). More advanced: Lists and tuples can store objects of any type .
list : List_name = [Item1, item2, Item3]
tuples : Tuple_name = (item1, item2, Item3)
What is the difference between a list and a tuple?
As can be seen in the structure, one is to use the [], one with ();
The main difference is that the tuple element is not modifiable! (When the function is mentioned)
List slices, Python uses: to slice content
List is a universal pocket, everything can be loaded inside, int,string, even inside can also nest a list
List lists have the method of increment and revise, the tuple tuple only expands with "+" (see Function and built-in function in detail)
Meta-group
Tuple (tuple) is a type of container that is very similar to a list.
Outwardly, it wraps the element in parentheses "()" rather than square brackets "[]".
Functionally: tuples are immutable types.
Tuples cannot be modified, and obviously additions, deletions, and modifications are not possible, only the view and delete (delete entire tuple) operation can.
There are three kinds of immutable types: numbers, strings, and tuples.
This comma can not be less, less error!
Dictionary (Key-value)
This should be nothing, there are everywhere.
The dictionary is the only hash type as Python.
Statement of the Dictionary
# Coding=utf-8 # The dict () function manufactures an empty dictionary adictt = {"name":"xx"" Location ":"xx"}
Operation of the Dictionary
Variable scope
The commented out print () is an error, not a statement, even if it declares something like a global variable
The first print out of the dogcat is inside the method
The last three printed values are the variable values at the time of declaration.
Logical control and operations
Judging If-else
The only thing to note is the colon following if and else :
Loop while, for
When using the while loop, also note the colon following the while condition :
Python does not have a + + operation, only num=num+1 or num+=1
For
The For loop is the same as the foreach inside C #, Note the colon:
List parsing
An array
movies = [ avata " , " , " titannic " , the Dark Knight rises " , " , " dances with Wolves " ]
If you do not use parsing, you must iterate over a list
for inch Movies: Print Movie
And after use, you can
If you want to get the first letter of each element and not use parsing, then this
If you use parsing, you can do this
Results:
Analytical:
The five operations
Functions and built-in functions
raw_input () function = input () function
Error, Nameerror:name ' raw_input ' is not defined, originally removed from version 3.0 of the Raw_input function, instead of input, so two functions are merged together.
The type () function returns the types of a parameter.
int () function transformation
Mathematical functions, introducing the Math module
Operation Function of List
-----------------------------Increase---------------------------------------------
The append () function adds an element to the last face of the list (increment)
The Extend () function expands a list as a parameter to the list of calls to him (increment)
The Insert () function specifies where to insert an element, where the original position and subsequent elements move one, two parameters one position, one inserted element ( increment )
-----------------------------Delete---------------------------------------------
Del () function parameter, passing in the ordinal of the element to be deleted (delete)
Note:del numbers must be added [index], otherwise the entire list variable will be removed
Remove () function parameter passed in explicit list element (delete)
Note: here Remove (1) Parameter 1, not the list subscript, but the first element of the list
-----------------------------Change---------------------------------------------
Change the words, simple very, direct element assignment
-----------------------------list operator---------------------------------------------
"+" Join operator (increment)
Similar to extend (), connect two lists
"*" Repeat operator (increment)
The list () function is used to generate an empty list, or to convert other data to a list, including tuples.
The tuple () function is used to generate an empty tuple, or to convert other data into tuples, including lists.
Custom functions
Def begins with: The end of the number, the function body is written below
The colon is still not small
Code style
1. Variable naming method (personal prefer small hump)
Small Hump MyName
Big Hump FirstName
_ Connect Last_Name
2. Indentation is important
Error
The end of the sentence can be no semicolon, but indentation to be correct, must be four, or you can define the space itself. Otherwise, the compilation will not let you pass!
3. Parentheses may not exist, such as IfElse, but the colon must not be less :
4. Notes
Note Chinese, if not identified, run will error
Need to add at the beginning
# Coding=utf-8
Reference:
Http://www.cnblogs.com/aehyok/p/3986168.html
Http://www.cnblogs.com/aehyok/p/3995120.html
Getting Started with Python