Differences between Ruby and Python (basic syntax)

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.

display

R:

puts "Hello World"

P:

print("Hello World")

formula

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")

Calculation formula answer

R:

10 / 3  

→3

P:

10 / 3

→ 3.3333…

Returns the value with the decimals truncated at //

10 // 3 

→ 3

if statement

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")

Repeat the same process

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

Differences between Ruby and Python (basic syntax)
Differences between Ruby and Python in scope
[Basic grammar] Differences between Ruby / Python / PHP
Ruby and Python syntax ~ branch ~
Difference between Ruby and Python split
Differences between Python, stftime and strptime
Differences in authenticity between Python and JavaScript
Differences in multithreading between Python and Jython
Ruby, Python and map
Python and Ruby split
Summary of the differences between PHP and Python
Python on Ruby and angry Ruby on Python
[Ruby vs Python] Benchmark comparison between Rails and Flask
Difference between Ruby and Python in terms of variables
Interprocess communication between Ruby and Python (POSIX message queue)
Python (Python 3.7.7) installation and basic grammar
I tried to enumerate the differences between java and python
Summary of Differences Between Ruby on Rails and Django ~ Basics ~
Differences between Windows and Linux directories
Difference between java and python (memo)
Difference between list () and [] in Python
Differences between yum commands and APT commands
Java and Python basic grammar comparison
Scraping with Node, Ruby and Python
Differences between symbolic links and hard links
Difference between python2 series and python3 series dict.keys ()
Python Basic Course (14 Modules and Packages)
Python --Difference between exec and eval
[Python] Difference between randrange () and randint ()
Differences between Python, read (), readline (), readlines ()
[Python] Difference between sorted and sorted (Colaboratory)
Difference in how to write if statement between ruby ​​and python
Summary of differences between Python and PHP (comparison table of main items)
Communicate between Elixir and Python with gRPC
difference between statements (statements) and expressions (expressions) in Python
Eating and comparing programming languages: Python and Ruby
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Python basic operation 3rd: Object-oriented and class
[Python3] Switch between Shift_JIS, UTF-8 and ASCII
[Python Iroha] Difference between List and Tuple
Encrypt with Ruby (Rails) and decrypt with Python
[python] Difference between rand and randn output
Matplotlib Basics / Differences between fig and axes
Differences between Numpy 1D array [x] and 2D array [x, 1]
Easy web scraping with Python and Ruby
I tried to touch Python (basic syntax)
Differences between Django's request.POST ['hoge'] and request.POST.get ('hoge')
SublimeText2 and SublimeLinter --Syntax check for Python3--
Correspondence between Python built-in functions and Rust
Exchange encrypted data between Python and C #
[Explanation for beginners] TensorFlow basic syntax and concept
Correspondence summary of array operation of ruby and python
Instant method grammar for Python and Ruby (studying)
The answer of "1/2" is different between python2 and 3
[python] Difference between variables and self. Variables in class
Specifying the range of ruby and python arrays
About the difference between "==" and "is" in python
Adjust font differences between Qt for Python OS
Basic Python writing