[JAVA] Differences in string processing between Python, Ruby, JS, PHP (combination and variable expansion)

When developing in many languages for hobbies and work Since there are many mistakes in writing with a simple syntax, I will transcribe it.

Only the reference and code are described without any explanation.

Combine string arrays

Python

str.join (iterable) — Python 3.8.1 documentation

strings = ['fizz', 'buzz'];
merged_strings = ' '.join(strings)
print(merged_strings) # 'fizz buzz'

Ruby

Array # join (Ruby 2.7.0 Reference Manual)

strings = ['fizz', 'buzz']
merged_strings = strings.join(' ')
p merged_strings # "fizz buzz"

JavaScript

Array.prototype.join() - JavaScript | MDN

const strings = ['fizz', 'buzz'];
const mergedStrings = strings.join(' ');
console.log(mergedStrings); // 'fizz buzz'

PHP PHP: implode - Manual

$strings = ['fizz', 'buzz'];
$mergedStrings = implode(' ', $strings);
print($mergedStrings) // 'fizz buzz'

Expression expansion in a string

Python

7.1.1. Formatted String Literal — Python 3.8.1 Documentation

string_fizz, string_buzz = 'fizz', 'buzz'
string_fizz_buzz = f'{string_fizz} {string_buzz}'
print(string_fizz_buzz) # 'fizz buzz'

Ruby

Expression expansion (Ruby 2.7.0 reference manual)

string_fizz, string_buzz = 'fizz', 'buzz'
string_fizz_buzz = "#{string_fizz} #{string_buzz}"
p string_fizz_buzz # "fizz buzz"

JavaScript

Template string --JavaScript | MDN

const stringF = 'fizz'
const stringB = 'buzz'
const stringFizzBuzz = `${stringF} ${stringB}`
console.log(stringFizzBuzz) // 'fizz buzz'

PHP

PHP: Parsing Variables --Manual

[$stringF, $stringB] = ['fizz', 'buzz'];
$stringFizzBuzz = "${stringF} ${stringB}";
print($stringFizzBuzz); // 'fizz buzz'

Recommended Posts

Differences in string processing between Python, Ruby, JS, PHP (combination and variable expansion)
Differences between Ruby and Python in scope
Differences in authenticity between Python and JavaScript
Differences in syntax between Python and Java
[Basic grammar] Differences between Ruby / Python / PHP
Differences in multithreading between Python and Jython
Differences between Ruby and Python (basic syntax)
Summary of the differences between PHP and Python
Grouping combination in Python / Ruby / PHP / Golang (Go)
Difference between Ruby and Python in terms of variables
Difference between Ruby and Python split
Difference between list () and [] in Python
Difference between == and is in python
Differences between Python, stftime and strptime
python string processing map and lambda
Difference in how to write if statement between ruby ​​and python
Summary of differences between Python and PHP (comparison table of main items)
Avoid nested loops in PHP and Python
difference between statements (statements) and expressions (expressions) in Python
Difference between PHP and Python finally and exit
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Divides the character string by the specified number of characters. In Ruby and Python.
Difference in writing method to read external source code between Ruby and Python
Get the last element of the array by splitting the string in Python and PHP
Differences between queryStringParameters and multiValueQueryStringParameters in AWS Lambda
How to embed a variable in a python string
[python] Difference between variables and self. Variables in class
I investigated in detail about variable processing in python
About the difference between "==" and "is" in python
Y / n processing in bash, python and Go
POST JSON in Python and receive it in PHP
Differences in behavior between append () and "+ =" operators when adding data to a list in Python
I want to embed a variable in a Python string
Full-width and half-width processing of CSV data in Python
AtCoder ARC080 D simulation solved in Ruby and Python
[Ruby vs Python] Benchmark comparison between Rails and Flask
Calculate Pose and Transform differences in Python with ROS
Mutual conversion between JSON and YAML / TOML in Python
Difference between return, return None, and no return description in Python
Handle prime numbers in Python / Ruby / PHP / Golang (Go)
Interprocess communication between Ruby and Python (POSIX message queue)
Compare "relationship between log and infinity" in Gauche (0.9.4) and Python (3.5.1)
Summary of date processing in Python (datetime and dateutil)
How to handle JSON in Ruby, Python, JavaScript, PHP
python variable expansion, format
File processing in Python
Multithreaded processing in python
String manipulation in python
Ruby, Python and map
Text processing in Python
Queue processing in Python
Python and Ruby split
Python string processing illustration
Mandelbrot Benchmark (C, PHP, HHVM, Ruby, Python, PyPy, and Kinx)
Overlapping combinations with limits in Python / Ruby / PHP / Golang (Go)
Python module num2words Difference in behavior between English and Russian
List concatenation method in python, difference between list.extend () and “+” operator
I tried to enumerate the differences between java and python
Factorial, permutations, (duplicate) combinations in Python / Ruby / PHP / Golang (Go)