"Basic Python Tutorial (second edition)" Learning notes
Basic part (1th chapter)
Ide
Windows:idle (GUI), Eclipse+pydev; Python (command line);
Linux/unix:python
>>> 1/2=0 note divisible by 0.
>>> from __future__ Import Division performing normal division
Python-qnew Perform a normal division
Divide, 1//2=0;% take the remainder;
Long integer: End with L
hexadecimal, beginning with 0x; octal starts with 0;
Variable name: letter, number, underline; Do not start with a number;
Print (42); Print 42; Output
X=input ("x:") input data returned to X
Import Math Imports Math module
From math import sqrt importing the SQRT function from the math module
Nan, not a number;
Import Cmath; complex math complex; imaginary numbers end with J;
*.py extension py
X=raw_input ("x:")
Python hello.py
Run the Python code file directly:
#!usr/bin/env python
#chmod a+x hello.py
#hello. py
Comments
string, either single or double quotation marks
Examples of strings: ' abc ', ' abc ', ' Ab ' CD ', ' AB ' CD ', ' AB ' CD ' EF ', ' ab\ ' CD '
Stitching strings:
x= "ABC" "DEF"
x= "ABC" ' DEF '
x= "ABC" + ' DEF '
To get a string from a value:
STR (123)
STR (123L)
Str (12.3)
STR (4+5)
REPR (123)
Repr (123L)
Repr (12.3)
Enter data from the keyboard:
Input (), raw_input ()
Multi-line string:
x= "AA"
Bb
CC ""
String Continuation Line
x= "aa\
Bb\
cc
To renew an expression:
X=1+2\
+3
Statement to continue:
Print \
' ABC '
Original string: R ' abc\def '
Unicode string: U ' ABC123 string '
Basic Python Tutorial (second edition) Learning Notes Basics section (Chapter 1th)