Everything is an object in Python too, but they aren't as useful as their Ruby counterparts e.g.
% python
Python 2.7.13 (default, Mar 20 2017, 13:35:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 2
>>> type(x)
<type 'int'>
>>> dir(x)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__'
+, '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__
+floordiv__', '__format__', '__getattribute__', '__getnewargs__', '__h
+ash__', '__hex__', '__index__', '__init__', '__int__', '__invert__',
+'__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__',
+ '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__'
+, '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__
+', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__'
+, '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__
+rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__s
+ub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bi
+t_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
>>> x.bit_length()
2
>>> x.denominator()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>>
>>> y = 'hello'
>>> type(y)
<type 'str'>
>>> dir(y)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__
+eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__
+getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__l
+e__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__',
+ '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '
+__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatte
+r_field_name_split', '_formatter_parser', 'capitalize', 'center', 'co
+unt', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format',
+ 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'ist
+itle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'r
+eplace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip'
+, 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title',
+'translate', 'upper', 'zfill']
>>>
>>> y.capitalize()
'Hello'
>>> y.__len__()
5
>>> len(y)
5
>>>
vs
% irb
irb(main):001:0> x = 2
=> 2
irb(main):002:0> x.methods
=> [:%, :&, :*, :+, :-, :/, :<, :>, :^, :|, :~, :-@, :**, :<=>, :<<, :
+>>, :<=, :>=, :==, :===, :[], :inspect, :size, :succ, :to_int, :to_s,
+ :to_i, :to_f, :next, :div, :upto, :chr, :ord, :coerce, :divmod, :fdi
+v, :modulo, :remainder, :abs, :magnitude, :integer?, :floor, :ceil, :
+round, :truncate, :odd?, :even?, :downto, :times, :pred, :bit_length,
+ :digits, :to_r, :numerator, :denominator, :rationalize, :gcd, :lcm,
+:gcdlcm, :+@, :eql?, :singleton_method_added, :i, :real?, :zero?, :no
+nzero?, :finite?, :infinite?, :step, :positive?, :negative?, :quo, :a
+rg, :rectangular, :rect, :polar, :real, :imaginary, :imag, :abs2, :an
+gle, :phase, :conjugate, :conj, :to_c, :between?, :clamp, :instance_o
+f?, :kind_of?, :is_a?, :tap, :public_send, :remove_instance_variable,
+ :singleton_method, :instance_variable_set, :define_singleton_method,
+ :method, :public_method, :extend, :to_enum, :enum_for, :=~, :!~, :re
+spond_to?, :freeze, :object_id, :send, :display, :nil?, :hash, :class
+, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untain
+t, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_meth
+ods, :protected_methods, :private_methods, :public_methods, :instance
+_variable_get, :instance_variables, :instance_variable_defined?, :!,
+:!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__]
irb(main):003:0>
irb(main):004:0* x.denominator
=> 1
irb(main):005:0> y = 'hello'
=> "hello"
irb(main):006:0> y.methods
=> [:include?, :%, :*, :+, :to_c, :unicode_normalize, :unicode_normali
+ze!, :unicode_normalized?, :count, :partition, :unpack, :unpack1, :su
+m, :next, :casecmp, :casecmp?, :insert, :bytesize, :match, :match?, :
+succ!, :+@, :-@, :index, :rindex, :<=>, :replace, :clear, :upto, :get
+byte, :==, :===, :setbyte, :=~, :scrub, :[], :[]=, :chr, :scrub!, :du
+mp, :byteslice, :upcase, :next!, :empty?, :eql?, :downcase, :capitali
+ze, :swapcase, :upcase!, :downcase!, :capitalize!, :swapcase!, :hex,
+:oct, :split, :lines, :reverse, :chars, :codepoints, :prepend, :bytes
+, :concat, :<<, :freeze, :inspect, :intern, :end_with?, :crypt, :ljus
+t, :reverse!, :chop, :scan, :gsub, :ord, :start_with?, :length, :size
+, :rstrip, :succ, :center, :sub, :chomp!, :sub!, :chomp, :rjust, :lst
+rip!, :gsub!, :chop!, :strip, :to_str, :to_sym, :rstrip!, :tr, :tr_s,
+ :delete, :to_s, :to_i, :tr_s!, :delete!, :squeeze!, :each_line, :squ
+eeze, :strip!, :each_codepoint, :lstrip, :slice!, :rpartition, :each_
+byte, :each_char, :to_f, :slice, :ascii_only?, :encoding, :force_enco
+ding, :b, :valid_encoding?, :tr!, :encode, :encode!, :hash, :to_r, :<
+, :>, :<=, :>=, :between?, :clamp, :instance_of?, :kind_of?, :is_a?,
+:tap, :public_send, :remove_instance_variable, :singleton_method, :in
+stance_variable_set, :define_singleton_method, :method, :public_metho
+d, :extend, :to_enum, :enum_for, :!~, :respond_to?, :object_id, :send
+, :display, :nil?, :class, :singleton_class, :clone, :dup, :itself, :
+taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?,
+:methods, :singleton_methods, :protected_methods, :private_methods, :
+public_methods, :instance_variable_get, :instance_variables, :instanc
+e_variable_defined?, :!, :!=, :__send__, :equal?, :instance_eval, :in
+stance_exec, :__id__]
irb(main):007:0>
irb(main):008:0* y.length
=> 5
irb(main):009:0>
|