Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write one-liners in Python? [closed]

Tags:

python

perl

I was going through the code golf question here on Stack overflow and saw many perl one liner solution.

My question is: Is something like that possible in Python?

like image 358
user485167 Avatar asked Oct 23 '10 20:10

user485167


People also ask

Can python be written on one line?

Programmers have to type relatively less and indentation requirements of the language makes them readable all the time. However, Python programs can be made more concise using some one-liner codes. These can save time by having less code to type.

How do you write a single line code in python?

Summary: To make a Python one-liner out of any multi-line Python script, replace the new lines with a new line character '\n' and pass the result into the exec(...) function. You can run this script from the outside (command line, shell, terminal) by using the command python -c "exec(...)" .

Can you jump lines in python?

Just add # at the beginning of all the lines you want to skip.

What does at end of a python line mean?

It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.


1 Answers

python -c 'print("Yes.")'

like image 154
Daenyth Avatar answered Oct 19 '22 02:10

Daenyth