Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    my $x = "2abc";
    my $y = $x + 42;
    print "x=", $x, " y=", $y, "\n";
    
  2. or download this
    Argument "2abc" isn't numeric in addition (+) at f.pl line 4.
    x=2abc y=44
    
  3. or download this
    x = "2abc"
    y = x + 42
    print "x=", x, "y=", y, "\n"
    
  4. or download this
    Traceback (most recent call last):
      File "f.py", line 2, in <module>
        y = x + 42
    TypeError: cannot concatenate 'str' and 'int' objects
    
  5. or download this
    x = "2abc"
    y = int(x) + 42
    print "x=", x, "y=", y, "\n"
    
  6. or download this
    Traceback (most recent call last):
      File "f2.py", line 2, in <module>
        y = int(x) + 42
    ValueError: invalid literal for int() with base 10: '2abc'
    
  7. or download this
    x = "2abc"
    y = int(x[0:1]) + 42
    print "x=", x, "y=", y, "\n"
    
  8. or download this
    x= 2abc y= 44
    
  9. or download this
    x = "2abc"
    y = x + 42
    print "x=", x, "y=", y, "\n"
    
  10. or download this
    f.rb:2:in `+': can't convert Fixnum into String (TypeError)
        from f.rb:2
    
  11. or download this
    x = "2abc"
    y = x.to_i() + 42
    print "x=", x, " y=", y, "\n"
    
  12. or download this
    x=2abc y=44