Simple comparison of Ruby and Python

Source: Internet
Author: User

Shortly before learning Ruby, I found that Ruby and Python were very much alike, so they were tested and compared, and they knew there was a ready-made online ... Here are the characteristics of the test results   sequence (including lists and tuples, etc.) with sharding: It may be convenient to extract the specific elements, temporarily feel useless: note is used: separate two numbers. The minus sign indicates the beginning or end of the countdown, and the shards in Python can be split evenly, in the format two colon Ruby is [4...7] so with two or three full periods Shard, also can use [the] this comma is different, Ruby does not seem to be equidistant division, And the meaning of the two parameters of the Ruby comma is that the first is the starting element sequence number, the second parameter is the length, while the two parameters in Python indicate that the first is the starting element sequence number, the second is the next paragraph starting element sequence number, and Ruby ... Similar to Ruby in the puts "Hello World" *4python also has the print "Hello World" of course python also has [42]*10, OK Ruby also has the sequence of the addition of a simple +python using Len (), Ruby uses. Lengthpython use in to check if a character is in a string, Ruby uses include? And all can be used to check the list/array, you can check whether a sequence in a sequence of Python using min (), Max (), Ruby uses. min. max, but ruby.min. Max can be followed by a small section with the parameter code to the minimum, maximum, second small value , the second big value and so on some simple processing. The string in Python cannot be modified directly, and the string in Ruby can be modified directly by using the list function to modify it, and the replacement element does not have to be the same as the replaced element, and it is assumed that the string in Ruby is a list of items stored in Python that deletes the list element using the Del List[] Ruby uses the. Deletepython Delete method can have delete specific [2], you can also delete a section [2:3],ruby can delete elements with specific content, such as: delete "word", the successful return of elements, failed to return nil, will directly change the list, Ruby removes the specified sequence number element as if there is no direct way to use list. Delete List "2"                               &N Bsp &nbsP      ruby can also be used simply to delete, but to use [] and delete does not change the array in substance, but the return element is deleted after the list of Python print console only with print, Ruby has print, puts, p# To read beautiful or to hit a tab bar ... python:          ruby:.append ()           <<     Push.count ()            . COUNT () extend ()           CONC At .index ()               Index.insert ()           &NBSP ;  .insert.pop ()                 Pop.remove ()         &NBS P  .delete/.delete_if{|blocks| Block}.reverse ()            .reverse.sort ()                . Sort python sort with key = Len This can be sorted in a particular way, with a specific sort (method). Ruby is sorted by using {|a,b| block}, a specific sort of python with "%s is it"% Stringruby with "#{string}" Python using input () and raw_input () Ruby using gets and gets . Chomppython. Find () returns the leftmost index of the substring's location//and inThe difference between Dex is that it can specify the starting point and the end point for Ruby to use. Indexpython uses the. Join () Ruby. Join effect is used by the join array python. Lower () Ruby is used. Downcase similar to:. Capitalize ()    .capitalize.upper ()          .upcase.swapcase ()    .swapcase.strip ()            .strip.lstrip ()           . Lstrip.rstrip ()           Rstrippython using import ruby with Requirepython and ruby power symbols * * All right combination supports sequence unpacking (multiple assignment) Python's If while Def has to be followed by a: Ruby doesn't, but Ruby has to have a endpython at the end elif = Ruby Elsifpython has = = is ruby has = = <=>//is is the ' identity operator ' both have assertions that Assertpython uses the for keys in dict to traverse the elements of the dictionary using Ruby. each{|k,v| block} Traversing Python exec can execute a string ruby is Eval//python eval is a string can be evaluated as an expression Ruby and Python support chained assignment:x=y=value     is different: Python has. Title Ruby does not have python. Islower (). Istitle (). Isupper () Python uses the Replace method to get the replaced string: Ruby can be replaced directly with the split format is split () and. Split python have. Translate () Maketrans () Ruby does not have Python support function multiple nesting, function name as a variable return, can be called Ruby also support multiple nesting, but return function name string, can not be called   python wordCode and Hashruby do not have a dictionary, Ruby only Hash python methods and Ruby methods are based on the location of the parameters, but Python can specify parameter name parameters (keyword parameters), at this time do not depend on the location.  python and Ruby Support indefinite parameters, the Python front plus *,ruby can be added *python before the indefinite parameters are implemented in tuples.

Ruby and Python simple comparison

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.