[PYTHON] I want to output to the console coolly

Sometimes I'm programming and want to know what's in a variable right now. In such a case, I think that I will output it to the console quickly and check it.

For example, like this.

Str name = "Demon Kogure"
int age = 100053

print( name + "Is your age" + age + "I'm old" )

Something like this ... It feels like I'm forcibly sticking a character string, and it's hard to read, isn't it? There are formats and writing methods for variable expansion in various languages, but how do you always write them? While thinking about it, it was awkward to look up, and in the end I repeated things like connecting with +.

So, this time, I investigated how to write variable expansion and format methods in each language. Since the purpose is to output to the console quickly, I will cast and convert the type to String type for the time being.

Java

String name = "Demon Kogure";
int age = 100053;
System.out.println(String.format("%s's age%I'm s years old.", name, age));
//Or (with a newline at the end)
System.out.printf("%s's age%I'm s years old.%n", name, age);

thx: @ saka1029

C#

string name = "Demon Kogure";
int age = 100053;
Console.WriteLine($"{name}Is your age{age}I'm old.");

Python

name = 'Demon Kogure'
age = 100053
print('{}Is your age{}I'm old.'.format(name,age))
#Or
print('%s's age%s years old' % (name,age))
#Or
print(f'{name}Is your age{age}I'm old.')

thx: @QUANON

Ruby

name = "Demon Kogure"
age = 100053
puts "#{name}Is your age#{age}I'm old."
#Or
puts "%s's age%I'm s years old." % [name, age]

thx: @scivola

JavaScript

var _name = "Demon Kogure";
var age = 1000053;

console.log(`${_name}Is your age${age}I'm old.`);
//Or
console.log("%s's age%I'm s years old.", _name, age)

thx: @hogefuga

PHP

$name = "Demon Kogure";
$age = 1000053;

echo "{$name}Is your age{$age}I'm old."

Rust

let name = "Demon Kogure";
let age = 100053;
println!("{}Is your age{}I'm old.", name, age);

thx: @scivola

Kotlin

val name = "Demon Kogure"
val age = 100053
println("${name}Is your age${age}I'm old.")

thx: @sdkei

Now you can output to the console coolly too.

Recommended Posts

I want to output to the console coolly
How to overwrite the output to the console
Keras I want to get the output of any layer !!
I want to handle the rhyme part1
I want to handle the rhyme part3
How to get colored output to the console
I want to use IPython Qt Console
I want to display the progress bar
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I want to output the beginning of the next month with Python
I want to handle the rhyme part7 (BOW)
I want to customize the appearance of zabbix
I want to use the activation function Mish
I want to display the progress in Python!
I want to see the file name from DataLoader
I want to grep the execution result of strace
I want to scroll the Django shift table, but ...
I want to solve Sudoku (Sudoku)
I want to inherit to the back with python dataclass
I want to fully understand the basics of Bokeh
I want to write in Python! (3) Utilize the mock
I want to handle the rhyme part6 (organize once)
I want to automate ssh using the expect command!
I want to publish the product at the lowest cost
I want to use the R dataset in python
I want to handle the rhyme part8 (finished once)
I want to increase the security of ssh connections
[TensorFlow] I want to master the indexing for Ragged Tensor
I want to use the latest gcc without sudo privileges! !!
I want to initialize if the value is empty (python)
I want to save the photos sent by LINE to S3
I want to automate ssh using the expect command! part2
maya Python I want to fix the baked animation again.
I want to move selenium for the time being [for mac]
I want to use only the normalization process of SudachiPy
I want to get the operation information of yahoo route
I want to change the Japanese flag to the Palau flag with Numpy
I want to calculate the allowable downtime from the operating rate
[Python] I want to use the -h option with argparse
I want to judge the authenticity of the elements of numpy array
I want to know the features of Python and pip
I want to make the Dictionary type in the List unique
I want to map the EDINET code and securities number
I want to align the significant figures in the Numpy array
I want to know the legend of the IT technology world
I want to create a Dockerfile for the time being.
I tried to output the access log to the server using Node.js
I didn't want to write the AWS key in the program
Post Jenkins console output to Slack
I want to understand systemd roughly
I calculated the stochastic integral (I to integral)
I want to scrape images to learn
I want to do ○○ with Pandas
I want to copy yolo annotations
I want to debug with Python
I tried to move the ball
I tried to estimate the interval.
I don't tweet, but I want to use tweepy: just display the search results on the console
I want to output a beautifully customized heat map of the correlation matrix. matplotlib edition