Python and Ruby features | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Python and Ruby features

Is there a feature in Python that is not in Ruby? (vice-versa) I know some, but I might not know the others

12th Apr 2017, 3:21 AM
MrCoder
MrCoder - avatar
9 Answers
+ 6
python: standard library, exception handling ruby: case statements, unless statements
12th Apr 2017, 7:06 AM
Supersebi3
Supersebi3 - avatar
+ 5
Hmm.. Seems about right, thanks :D
12th Apr 2017, 7:14 AM
MrCoder
MrCoder - avatar
+ 5
There are a number of other useful methods available for manipulating arrays. Here are some of the most used ones: array.length or array.size returns the number of elements in array. array.sort returns a new array with the elements sorted array.uniq returns a new array with duplicate values removed from array. array.uniq! removes duplicates in place. array.freeze safeguards the array, preventing it from being modified. array.include?(obj) returns true if obj is present in array, false otherwise. array.min returns the element with the minimum value. array.max returns the element with the maximum value. this text, copied from Ruby course > Collections > Array manipulations, includes some built-in array functions in ruby that aren't in python. but you can rebuild most: array.length - len(list) array.include?(x) - if x in list: array.min - min(list) array.max - max(list) probably more, but too lazy now
12th Apr 2017, 7:28 AM
Supersebi3
Supersebi3 - avatar
+ 5
another thing in ruby that python doesnt have are in-place operators, for example: array.reverse! would be done in python using list = list[::-1] as you see, list is reassigned, array isnt. but, as The Zen of Python states: Explicit is better than implicit. edit: There is actually the in-place method list.reverse()...
12th Apr 2017, 7:31 AM
Supersebi3
Supersebi3 - avatar
+ 5
also, ruby has some additional loops: arr.each do - for i in list: loop do - while True: x.times do - for i in range(x):
12th Apr 2017, 7:32 AM
Supersebi3
Supersebi3 - avatar
+ 5
python, on the other hand, has explicit type conversion. until now, i have no idea what the ruby equivalents of str(x), float(x), bool(x), list(x), dict(x), tuple(x) etc are. ruby has the .to_s(x) method, that helps with easy conversion between numeric systems
12th Apr 2017, 7:35 AM
Supersebi3
Supersebi3 - avatar
+ 5
btw if youre wondering im going through the ruby course and posting everything i notice here
12th Apr 2017, 7:36 AM
Supersebi3
Supersebi3 - avatar
+ 4
I also think you can't operate with arrays in python as much as it lets you in ruby.
12th Apr 2017, 7:20 AM
JRE
JRE - avatar
+ 4
@JRE I've noticed that too I forgot what it is but I know that you cant do something in Python but you can in Rubu
12th Apr 2017, 7:23 AM
MrCoder
MrCoder - avatar