[Learn] Python Core Programming Learning Notes (ii)

Source: Internet
Author: User

2. Python Start 2.1 Print

1 Print " Hello world! "

2.2

_: The value of the last expression

>>: Output redirection

%: Prints the formatted string and values for the style, and the value after% is a tuple object, with "()" containing the

Print "%s is a number%d."%  ("Python", 6)ImportSYSPrint>> Sys.stderr,"msg"file= Open ("filename","a")Print>> file,"File MSG."file.close () Hello= Raw_input ("Hello:")Print "Num:%d."% (int (hello))

2.3

#: Comment Symbol

2.4 operator

+-*///% * *

< <= > >= = = = = <>

And Or not

* *: exponentiation

2.5 Variables and Assignments

2.6 Numbers

int long bool Float complex

Decimal

Import Decimal

Decimal. Decimal ("1.1")

1.1-1.1000001 (usually counted as such)

2.7 string

Support for [],[:] Operations

2.8 Lists and tuples

Index starting from 0, support slicing operation ': '

List: [] can change values

Tuple: () cannot change value

2.9 Dictionaries

{' key ': ' Value '}

2.10 Code blocks aligned with indentation

  

2.11 If

  

if condition:    something

2.12 while
 while condition:    something

2.13 for
 for iteration:    something

Range (): extent

Enumerate (): Enumeration

2.14

  

 for inch if  not x% 2]

2.15 Open () file ()
Fobj = open ("Filename""R") for in fobj:      print Eachline,      #  ', '  causes print to not print line breaks fobj.close ()

2.16 Exceptions
Try :    somethingexcept  IOError, E:    except

2.17 Functions
def function_name ():    something

Class 2.18
class ClassName (baseclassname):    something

2.19 Modules
Import Module_name

2.20 Utility Functions
Dir ([obj]) help ([obj]) int () Len () Open () range () raw_input () str () type ()

[Learn] Python Core Programming Learning Notes (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.