Currently, I am attending TECH CAMP and learning Python by myself while learning Ruby. Regarding the difference between Ruby and Python, I will output the basic syntax as a memorandum.
R:
puts "Hello World"
P:
print("Hello World")
R:
price = 100
puts "The total is#{price}It's a yen"
P:
price = 100
print(f"The total is{price}It's a yen")
R:
10 / 3
→3
P:
10 / 3
→ 3.3333…
Returns the value with the decimals truncated at //
10 // 3
→ 3
R:
if number >= 10
puts "More than 10"
elsif number >= 0
puts "0 or more and less than 10"
else
puts "Less than 0"
end
P:
if number >= 10:
print("More than 10")
elif number >= 0:
print("0 or more and less than 10")
else:
print("Less than 0")
Regarding the following array (list)
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
R:
nums.each do |num|
puts num
end
P:
for num in nums:
print(num)
Recommended Posts