Python Devs Will HATE You If You Use THIS Syntax

preview_player
Показать описание
Python devs with hate you if you use this syntax. #Python #Shorts #Code
Рекомендации по теме
Комментарии
Автор

wanna see my one liner? its past column 80 tho....

Aiden-rzvf
Автор

PEP 8 is the official style guide and says:

Compound statements (multiple statements on the same line) are generally discouraged.

poyrjuha
Автор

Perfect for one-liners eg upgrading a shell:
Python3 -c 'import pty; pty.spawn("/bin/bash")'

serepax
Автор

Put things in a single line is strange even in languages that uses semi-colon to separate the statements, like C++ and C# .

erick_falker
Автор

It's like when i discovered that in JavaScript you don't need to put semicolon at the end of a line, it just feels wrong

SirusStarTV
Автор

You definitely don’t wanna use it in regular code. Although it is useful for running short python scripts in the shell.

AWriterWandering
Автор

I've used this for writing
import pdb; pdb.set_trace()
in code that I want to debug but can't push to my feature branch with the import statement at the top. Having it on one line makes it easier to delete all at once

infernape
Автор

There's another trick, you can continue the line after colons, and it works as if you've indented them.
I sometimes use these for short inline statements, like so:
if condition: call_function()

kingadayaday
Автор

I often get confused and put semicolon, especially if I just switched to Python from a language like C or Java.

ntlake
Автор

Semicolons are useful when you invoke non-interactive python.
E.g.: python -c 'import math; print(math.pi)'

drugndrop
Автор

I would generally avoid doing this. The only time I would do it is if I have a case like in this video, where we have a variable and just want to print it out without doing anything to it

shock
Автор

A lot of my code is "unpythonic" but to be honest, I think too much rigidity is harmful to the creative side of problem solving, and I would not have come up with some of the interesting, intelligent and creative systems I have if I had stuck solidly to the python convention. I wrote a whole custom language parser in python, that itself is pure python code, but also resembles grammar rules, and it could not be less pythonic, but its tat, intuitive etc. THis syntax here, is really useful for when you want to add temporary statements etc and make them stand ut from the normal flow of the program. This can be more readable for things like testing and refactoring etc.

AlyceIsFree
Автор

I remember when I moved onto C++ after 3 years of experience with Python. Someone said that Python would "mess up my syntax" because "there are no semicolons in Python". Well that didn't age well for them, as I tried learning C++ in the past. But I never really understood it until I learned it from scratch again a few months ago. And rarely forget to put semicolons at the end of each line (I mainly forgot to put a semicolon when I declare a class, because functions aren't declared like that).

I sometimes use semicolons in Python, but it would depend on what I'm doing. If I'm using let's say the Pythonnet package (it's a Python package for having .NET syntax in Python, and Python syntax in C# or F#), that's where I would use it. But other than that I wouldn't use semicolons much in Python.

pyp
Автор

"Pythonic code" is just a bad ass unreadable code that some guy copypasted from stack overflow

fernandobalieiro
Автор

I like it, Python identatiom is 1 big reason that made me reject to learn it since 200x

vietle
Автор

I think you can do similar thing with if statmemts. You can write it on one line
if a > 3: a = 3

Oler-yxxj
Автор

I use it often. If I need to import module and execute it right away, I always use semi-colon (;).

thelostman
Автор

Semicolons are strongly required for system administrators to write scripts. And yes, you need to use the programming language correctly. If you use it for programming, then you do not need to put a semicolon!

eugenex
Автор

When u get an error, u wont know which line for fast debug

trke
Автор

I use it rarely for quick operations and then print the updated output.
For example:
Zero_arr = np.zeros((3, 3))
Updated_arr = zero_arr[:, 2], print(updated_arr).

archismanchakraborti