A Java-developed Python path -------------- (1 ),

Source: Internet
Author: User

A Java-developed Python path -------------- (1 ),

I recently started to learn Python, mainly because I am writing a cmdb o & M management platform for HNA through JAVA. I am the only developer sitting in the O & M room, and I am also a father and mother, front-end, backend, test, design, requirements,

Release all !! I have also searched related CMDB on GitHub, but most of them are written through Python, so I have always been an impulse to learn Python. Well, I don't need to talk about it, in the future, I will write basic things about Python for a long time, but also some things, which are different from those of JAVA ~~

 

 

First, define a variable. I have to say that, as a weak language, it is really invincible. For example, define a variable.

I = 0 or I = "abc"

Unlike JAVA, which requires a String or an int,

Input: input = ("What You Want to input ")

Then the JAVA is:

System. out. printlin ("the stuff you want to enter ");

Pipeline SC = new pipeline (System. in );

String context = SC. nextLine ();

System. out. println ("data" + context)

Is it a lot of trouble ~~

 

Note: single line comment of P #, single line comment of multi-line comment "J //, multi-line comment /**

List: The P list is [xxx] J's [xxx] is an array, which is also a group of stored arrays. The basic usage is similar

Dictionary is available when a list is available ~ The usage is similar. They are both in the form of {key: value} and can also be nested in multiple layers.

What boolean values and operators are the same +-*/%> =,

There is an interesting placeholder, for example:

Print ('My name is % s, My age is % s' % ('A', 18), which is in Python.

Then there is If... else. For example, if there are other branches, P is elif J is else If
Then P is all: end this line J is; end this line, nothing else to say
Then the usage of while is similar, and then there is a while... else in P.


What surprised me most is that it is too convenient for Python to read and write files.
Read files:

With open('db.txt ', 'R') as f:


Write File:

With open('db.txt ', 'A') as f:
F. write ("What You Want to write ")
It's easy


Then read and write files in JAVA:
First, you need to create a low-level Stream object, create a high-level stream, create a new self-object, new byte [1024], read one byte and one byte, and flush.
When writing a file, the advanced stream, low-level stream, and outputstream are written in one byte and flush.
And close the stream.

Then, Python uses the with open method and does not need to close the stream, which saves time. It is worth noting that reading is carried with 'R' and writing with 'A'

 

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.