[PYTHON] [Programming learning] Logic comparison by language part.2 (variables: numbers, character strings)

Until the declaration of character strings (String) and numerical values (Int) and the confirmation of the process of outputting them at the same time.

2. Variables

Ruby

sample.rb


#The comment line is"#"Described in
moji = "ABC" #String
suji = 123 #Numerical value

#This way of writing is NG
# puts moji + suji

#This way of writing is OK
puts moji + suji.to_s
$ ruby sample.rb
ABC123

Python3

sample.py


moji = "ABC"
suji = 123

#This way of writing is NG
# print(moji + suji)

#This way of writing is OK
print(moji + str(suji))
$ python test.py
ABC123

Swift

sample.swift


import Foundation
var moji = "ABC"
var suji = 123

//This way of writing is NG
//print(moji + suji)

//This way of writing is OK
print(moji + String(suji))
(playground)
ABC123

Java

sample.java


package sample;

public class Main {
    public static void main(String[] args) {
        String moji = "ABC";
        int suji = 123;

        //Java is OK with this writing style
        System.out.println(moji + suji);
    }
}
(eclipse console)
ABC123

C#

sample.cs


using System;
public class HelloWorld {
    static public void Main () {
    	String moji = "ABC";
    	int suji = 123;
    	
    	// C#This way of writing is OK
        Console.WriteLine(moji + suji);
    }
}

(Execute using'mono'in the execution environment at hand)

$ mcs sample.cs
(Compile successful)
$ mono sample.exe
ABC123

The content I'm learning is ahead of me, so I want to output more and more.

Recommended Posts

[Programming learning] Logic comparison by language part.2 (variables: numbers, character strings)
[Programming learning] Logic comparison by language part.1 ("Hello World")
[Programming learning] Logic comparison by language part.3 (conditional branching)
[2019 latest version] Programming language comparison
Making sound by programming Part 2
Stack processing speed comparison by language