From python to Ruby)

Source: Internet
Author: User

PythonIs a very good language, fromPythonMigrateRuby, You will find some Syntactic differences.

 

Similarity

 

AndPythonSimilarlyRubyMedium,...

  • There is an interactive prompt(CalledIRB ).

  • You can read the document in the command line.(PassRiCommand to replace
    Pydoc ).

  • No special end line symbol(Except for new lines).

  • The text can contain multiple lines, just likePythonThree quotation marks in.

  • ListUse[],DictUse{} (DictInRubyCalled"Hashes ").

  • ArraysSame way of working(2ItemsArrayAdd to a longerArray,HoweverA3 = [a1, a2]Merge to generate an array containing arrays.).

  • ObjectsThere are fixed types and dynamic Conversions.

  • Everything isObject,The variable name only pointsObjectPointer.

  • Different keywords,HoweverExceptionsDoes not change.

  • You have embedded document tools
    (InRubyCalledRdoc ).

 

Differences

 

AndPythonDifferent,InRubyMedium,...

  • StringsYes.

  • You can use Constants(The constant value varies.).

  • Some mandatory writing requirements(For example:ClassThe name must start with an uppercase letter.,Variable name starts with a lowercase letter).

  • There is only one container.(Array ),
    And it can be changed.

  • In quotation marksStringThe limits are different.

  • There is no new styleClass,ClassThere is only one style.

  • You cannot directly access the attribute.RubyIs implemented through method calls.

  • Using () in a method call is an optional policy.

  • Used herePrivateAnd so on.PythonIn.

  • "Mixin's"Used to replace multiple inheritance.

  • You can modify the existingClassAnd add a new method.

  • UseTrueAndFalseTo replaceTrueAndFalse
    (UseNilTo replaceNone).

  • When determining the true value,OnlyFalseAndNilWill be considered false.All others think it is true(Including0, 0.0 ,"",And[]).

  • UseElsifSubstitutionElif.

  • UseRequireSubstitutionImport.However, the usage is the same.

  • UseUsual-styleTo comment out the document(SubstitutionDocstrings)It is also used to generate documents.

 

 

Original article address:

Http://www.ruby-lang.org/zh_CN/documentation/ruby-from-other-languages/to-ruby-from-python/

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.