Basic usage Instructions for Python

Source: Internet
Author: User

1. First define a called module, file name cnf.py

#!/usr/bin/env python2. 7 #coding=utf-8"utf-8"  ) class CNF (Object ):    'test'    def getInfo (self):        " The getInfo function of the CNF is called here "

2. Keynote module

" "The default encoding format in Python is the ASCII format, which fails to print correctly when the encoding format is not modified, so the error occurs when reading Chinese. The workaround is to add # at the beginning of the file-*-coding:utf-8-*-or #coding =utf-8it's all right." "#-*-coding:utf-8-*-  # /usr/bin/EnvPython # import module Cnfimport cnfclass Test (Object): # global variable name name="Global _name"# Construct initialization variable def __init__ (self): # initialize P1 to Test yourself self.p1="AAAA"# Print the value of the global variable name, here in a different way than the Java constructor usage # in Java You can use SYSTEM.OUT.PRINTLN (name) directly;        # instead of using System.out.println (Test.name); Print Test.name
# Copy the Cnf class in the CNF module to Test yourself, self.cnf=CNF. CNF () def used (self): print self.p1 print Test.name# Call Test yourself in the constructor to initialize the good CNF object and use the GetInfo () method print Self.cnf.getInfo () #静态类 @classmethod def Sssed (self): print"a static method is called Sssed"def Main (): # Instantiate Test object T=Test () t.used ()
# call static method sssed () test.sssed ()if__name__ = ='__main__': Main ()

Basic usage Instructions for Python

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.